为什么推不更新列表

时间:2013-12-19 06:22:28

标签: html angularjs

的javascript

$scope.addCustomer = function() {    
    $scope.customers=[{name:'bob',city:'delhi'},{name:'david',city:'bombay'}];
    $scope.customers.push({name:$scope.newCustomer.name,city:$scope.newCustomer.city
}

HTML

<br/>
Customer name :<br />
<input type="text" ng-model="newCustomer.name" />
<br/>
Customer city :<br />
<input type="text" ng-model="newCustomer.city" />
<button ng-click="addCustomer()">Add customer</button>

我尝试在无序列表中列出所有客户名称,但新客户未添加到列表中。

如何将niew客户添加到列表中?

2 个答案:

答案 0 :(得分:0)

试试这个:

$scope.customers=[{name:'bob',city:'delhi'},{name:'david',city:'bombay'}];
$scope.addCustomer = function() {
    $scope.customers.push({name:$scope.newCustomer.name,city:$scope.newCustomer.city});
}

工作示例:{{3p>

答案 1 :(得分:0)

请勿在{{1​​}}中为$scope.customers分配值。

你可以试试这个:

addCustomer()