Angular TypeError:无法在字符串''上创建属性

Cri*_*alu 8 angularjs

单击"添加"后尝试清除输入框,就像 本教程中的人员一样.
我使用这个简短的代码重新创建了错误,而没有使用API​​.
您还可以查看Plunker.

HTML

<input ng-model="contact.name" type="text">
<button ng-click="Add()">Add</button>

<ul ng-repeat="contact in contactList">
    <li>{{ contact.name }}</li>
</ul>
Run Code Online (Sandbox Code Playgroud)

JS

$scope.contactList = [
    {name: 'cris'}, {name: 'vlad'}
;]

$scope.Add = function() {
    $scope.contactList.push($scope.contact)
    $scope.contact = ""
}
Run Code Online (Sandbox Code Playgroud)

似乎我可以添加1项,但在第二个我得到此错误: 在此输入图像描述

Mis*_*lis 15

你没有contact以正确的方式清理你的物体.在该Add()功能中,更改:

$scope.contact = ""
Run Code Online (Sandbox Code Playgroud)

至:

$scope.contact = {};
Run Code Online (Sandbox Code Playgroud)

叉式弹药