w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
bind input to object array in angular

I would create a button that on ng-click="storeNames(nameInput, manager).

.split() takes a string and separates it into elements of an array every time it sees a selector (which in this case is ', ')

http://www.w3schools.com/jsref/jsref_split.asp

    $scope.nameInput = '';
    $scope.managers = [
            {
            managerName: 'Billy Joe',
            employeesList: [
                { employeeName: 'Joe', employeeCategory: 'Developer' },
                { employeeName: 'Bob', employeeCategory: 'Developer' }
                ]
            }
        ];

    $scope.storeNames = function(names, manager) {
        if(names.length > 0) {
            names.split(", ");
            for(var x = 0; x < names.length; x++) {
                manager.employeesList.employeeName[x] = names[x];
            }
        }
    }




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.