[英]ng-list in angularJS is not working as expected
我有以下代碼
<input class="fill" name="keywords" ng-model="textbook.keywords"
type="text" ng-list="," ng-required="true"></input>
其中,bookbook.keywords是字符串數組。
我希望上面的代碼創建一個文本框,其中填充了以逗號分隔的數組textbook.keywords值。 而是,文本框為空。 我通過調試確保textbook.keywords中具有值。
第一:請檢查該庫是否正確添加到index.html
。
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
第二:請檢查ng-app
是否在HTML中正確添加:
<html ng-app="listApp">
第三:請檢查ng-controller
是否在HTML中正確添加:
<body ng-controller="ListCtrl">
第四: app.js
應該包含以下最小代碼:
var app = angular.module('listApp', []);
app.controller('ListCtrl', function($scope) {
$scope.textbook = {
keywords: ['Text1', 'Text2', 'Text3']
};
});
第五:別忘了在index.html
添加app.js
<script src="app.js"></script>
最終:在此處添加了工作代碼段:
var app = angular.module('listApp', []); app.controller('ListCtrl', function($scope) { $scope.textbook = { keywords: ['Text1', 'Text2', 'Text3'] }; });
<html ng-app="listApp"> <head> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> </head> <body ng-controller="ListCtrl"> <input class="fill" name="keywords" ng-model="textbook.keywords" type="text" ng-list="," ng-required="true"> </body> </html>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.