簡體   English   中英

angularJS中的ng-list無法正常工作

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM