Javascript 无法读取angular js中的属性
这是我的脚本文件Javascript 无法读取angular js中的属性,javascript,html,angularjs,Javascript,Html,Angularjs,这是我的脚本文件 app.controller('userController', function PostController($scope, userFactory) { $scope.users = []; $scope.user = { items : [] }; $scope.editMode = false; $scope.addItem = function () { $scope.user.it
app.controller('userController', function PostController($scope, userFactory) {
$scope.users = [];
$scope.user = { items : [] };
$scope.editMode = false;
$scope.addItem = function () {
$scope.user.items.push({
Name: $scope.newItemName,
Value: $scope.newItemValue
});
};
$scope.deleteItem = function (index) {
$scope.user.items.splice(index, 1);
};}
这是我的html文件
<div class="form-group">
<ul class="nav">
<label for="title" class="col-sm-2 control-label">Items</label>
<div class="col-sm-10">
<input type="text" value="ItemName" class="form-control" id="title" ng-model="newItemName" required placeholder="name of new item...">
<input type="text" value="ItemName" class="form-control" id="title" ng-model="newItemValue" required placeholder="name of new item...">
</div>
<button ng-click="addItem()">Add Me</button>
<li ng-repeat="item in user.items">
<a href="#">{{item.Name}}</a> <a ng-click="deleteItem($index)" class="delete-item">x</a>
</li>
</ul>
</div>
我搞不懂这个错误以及它发生的原因。请帮助我,我是angular js的新手发生错误的原因是您的
用户
属性为空:
$scope.user = null;
将其更改为理想情况下具有items属性的实际对象:
$scope.user = { items : [] };
发生错误的原因是
用户
属性为空:
$scope.user = null;
将其更改为理想情况下具有items属性的实际对象:
$scope.user = { items : [] };
发生错误的原因是
用户
属性为空:
$scope.user = null;
将其更改为理想情况下具有items属性的实际对象:
$scope.user = { items : [] };
发生错误的原因是
用户
属性为空:
$scope.user = null;
将其更改为理想情况下具有items属性的实际对象:
$scope.user = { items : [] };
如果您有
$scope.user=null,则项目的位置很简单代码>
这么简单做一件事添加
$scope.user = {items:[]};
然后使用$scope.user.items.push(数据)
如果您有$scope.user=null,那么简单地使用where is items代码>
这么简单做一件事添加
$scope.user = {items:[]};
然后使用$scope.user.items.push(数据)
如果您有$scope.user=null,那么简单地使用where is items代码>
这么简单做一件事添加
$scope.user = {items:[]};
然后使用$scope.user.items.push(数据)
如果您有$scope.user=null,那么简单地使用where is items代码>
这么简单做一件事添加
$scope.user = {items:[]};
然后使用$scope.user.items.push(数据)
您的$scope.user=null;应该与$scope.user={}类似;这是因为您的“items”对象不存在;应该与$scope.user={}类似;这是因为您的“items”对象不存在;应该与$scope.user={}类似;这是因为您的“items”对象不存在;应该与$scope.user={}类似;这是因为你的“items”对象不存在,OP.你试图循环通过一个为空的变量Hehe,你赢了我几秒钟:D+1为你:)@FeroozKhan你确定你更新了所有内容吗?这是一个答案,是我自己,还是我在你提供的代码笔链接中没有发现任何错误?呵呵,你比我快了几秒钟:D+1为你:)@FeroozKhan你确定你更新了所有内容吗?这是一个答案,是我自己,还是我在你提供的代码笔链接中没有发现任何错误?呵呵,你比我快了几秒钟:D+1为你:)@FeroozKhan你确定你更新了所有内容吗?这是一个答案,是我自己,还是我在你提供的代码笔链接中没有发现任何错误?呵呵,你比我快了几秒钟:D+1为你:)@FeroozKhan你确定你更新了所有内容吗?这是一个问题,是我自己的问题,还是我在你提供的代码笔链接中没有发现任何错误?我正在编辑我的脚本文件,同样的错误也会发生@Squiroi在编辑我的脚本文件时发生了相同的错误@Squiroi在编辑我的脚本文件时发生了相同的错误@Squiroi在编辑我的脚本文件时发生了相同的错误@蠕动