RudziankoŇ≠ RudziankoŇ≠ - 1 year ago 188
AngularJS Question

AngularJS: TypeError: Cannot set property of undefined

Probably I completely don't understand Angular. My question is:

On UI I have following:

<input ng-model="$ctrl.newItem.action" id="action" name="action" class="form-control"/>

element is two-ways binded to angular model.

Now in the other part of UI but with the same controller I call edit method:

$ctrl.updateItem = function (item) {
$ctrl.newItem.action = item.action;

I would like
show action of currently being edited element bu instead i see error in console:

TypeError: Cannot set property of undefined

is undefined?

Answer Source

angular models undefined until you define it in controller or type something in input

try this one

$ctrl.updateItem = function (item) {
            $ctrl.newItem = {action: item.action};
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download