Link to home
Start Free TrialLog in
Avatar of JElster
JElsterFlag for United States of America

asked on

AngularJS - Factory to Set & Get Array / key value

What's the syntax/code to create a factory to hold an array.
Key/Values..

I want to set / get an array of

LASTNAMES
FIRSTNAMES


Be able to add to the array and delete from the array.

Here's I think how you would do a single

thx




angular.module('app').factory('testFactory', function() {
    var name = '';
    var last_name = '';
    var color = '';

    function setData(n, ln, c) {
        name = n;
        last_name = ln;
        color = c;
    }

    return {
        name: name,
        last_name: last_name,
        color: color,
        setData: setData
    }
})
ASKER CERTIFIED SOLUTION
Avatar of Alexandre Simões
Alexandre Simões
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JElster

ASKER

Hi..
So how would I set these values?

Key                          Value
name                   Simoes
name                     Smith



testFactory.setData( name: 'Simoes' );

testFactory.setData( name: 'Smith' );
Where's the key?
How are you supposed to get the values?