當用戶在輸入字段中鍵入任何內容並單擊添加按鈕時,輸入將添加到數組中並顯示在列表中。如何清除AngularJs中的輸入字段?
但是我不能清除輸入字段後推入陣列。
我是AngularJs的新手,希望能有所幫助。 在此先感謝。
這裏是我的代碼:
<div class="container">
<div ng-controller="mainController">
<input type="text" ng-model='name' placeholder="name">
<input type="text" ng-model='number' placeholder="number">
<button ng-click="addToList()">Add</button>
<ul ng-repeat="person in array_of_Names">
<li>{{$index + 1}}.Name:{{person.name}},Phone:{{person.number}}</li>
</ul>
</div>
</div>
而且我app.js:
var myApp = angular.module('myApp', []);
myApp.controller('mainController',['$scope',function($scope){
$scope.array_of_Names = [];
$scope.addToList = function(){
var person = {
name: $scope.name,
number: $scope.number
};
$scope.array_of_Names.push(person);
};
}]);
'$ scope.name = null'? –