我是 AngularJS 的新手,我正在四处寻找我能做什么。我有一个简单的表格:
<div ng-controller="EditContactCtrl">
<div class="row-fluid" ng-repeat="email in contact.emails">
{{email.type}} - {{email.email_address}}
</div>
<form name="emailForm" ng-controller="EditContactCtrl" ng-submit="addEmail()">
<select class="span4" name="type">
<option vlaue="Work">Work</option>
<option vlaue="Personal">Personal</option>
<option vlaue="Other">Other</option>
</select>
<input class="span6" type="text" name="email_address" placeholder="Email Address">
<input type="submit" class="btn span2 pull-right" value="Add"/>
</form>
</div>
在控制器中,我有一个简单的操作来将新的电子邮件地址推送到联系人对象上,例如
function EditContactCtrl($scope, Contacts, $routeParams){
$scope.contact = {emails:[], contact_numbers: [], addresses: []};
$scope.isNew = $routeParams.contactId == '';
if(!$scope.isNew){
$scope.contact = Contacts.get({contactId: $routeParams.contactId});
}
$scope.addEmail = function(){
$scope.contact.emails.push({type:emailForm.type.value, email_address: emailForm.email_address.value});
console.log($scope.contact.emails);
emailForm.reset();
}
}
当我运行这段代码时,一切都很好,我可以看到新的电子邮件地址被添加到联系人对象的电子邮件列表中。但问题是 UI 没有使用新的电子邮件地址进行更新。我期待它在我拥有的地方吐出上面的新地址ng-repeat="email in contact.emails"