也许我完全不懂Angular。我的问题是:AngularJS:TypeError:无法设置属性undefined
在UI我有以下几点:
<input ng-model="$ctrl.newItem.action" id="action" name="action" class="form-control"/>
所以action
元素绑定到角模型两方面。
现在,在UI的但具有相同的控制器,另一部分我称之为编辑方法:
$ctrl.updateItem = function (item) {
$ctrl.newItem.action = item.action;
//...
我想当前正在编辑元素的$ctrl.newItem.action
表演动作BU相反,我看到的错误控制台:
TypeError: Cannot set property of undefined
为什么$ctrl.newItem.action
未定义?
尝试在HTML视图中删除$ ctrl – RL89
提示:它不会抱怨'$ ctrl.newItem.action'未定义,它抱怨'$ ctrl.newItem'未定义。 – Icycool
如果我们看到您要实现的代码示例,那么您在哪里编写了'$ ctrl.newItem.action = item.action;'?控制器功能里面? – Dabbas