【发布时间】:2019-11-26 19:57:28
【问题描述】:
这是我的笨蛋, https://plnkr.co/edit/stKf1C5UnCKSbMp1Tyne?p=preview
angular.module('listExample', [])
.controller('ExampleController', ['$scope', function($scope) {
$scope.names = ['morpheus', 'neo', 'trinity'];
}]);
<body ng-app="listExample">
<form name="myForm" ng-controller="ExampleController">
<label>List: <input name="namesInput" ng-model="names" required></label>
<br>
<tt>names = {{names}}</tt><br/>
</form>
</body>
$scope.names是一个数组,在html的输入字段中显示时显示为morpheus,neo,trinity
但是如何在 html 输入字段中显示为["morpheus","neo","trinity"]
当在输入字段的数组中添加或删除元素时,用新值更新 $scope.names
【问题讨论】:
标签: javascript angularjs angularjs-directive