也許我完全不懂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