這裏怎麼能是我的代碼,在NG-重複我的字符串值綁定在angularJS
$scope.records = "test,Test1,Test2,test3,test4";
我想在L1標籤這個值與像NG-repeat.need輸出中綁定爲
.test
.Test1
.Test2
.Test3
.Test4
這裏怎麼能是我的代碼,在NG-重複我的字符串值綁定在angularJS
$scope.records = "test,Test1,Test2,test3,test4";
我想在L1標籤這個值與像NG-repeat.need輸出中綁定爲
.test
.Test1
.Test2
.Test3
.Test4
您可以使用split經營者拆就,
字符串,那麼你可以使用NG-重複
angular.module('myApp', []);
angular.module('myApp').controller('MyController', MyController);
function MyController($scope) {
$scope.records = "test,Test1,Test2,test3,test4";
$scope.records = $scope.records.split(',');
};
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.10/angular.min.js"></script>
<div ng-app="myApp" ng-controller="MyController">
<ul>
<li ng-repeat="record in records">
{{record}}
</li>
</ul>
</div>
請檢查您需求量的工作plnkr http://plnkr.co/edit/cmY8S1nKYDBCa1GvmFh6?p=preview
<ui>
<li ng-repeat="record in records" ng-bind="record"></li>
</ui>
使用ng-bind
var app = angular.module("app", []);
app.controller("ctrl", function($scope) {
$scope.records = ["test", "Test1", "Test2", "test3", "test4"];
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
<li ng-repeat="rec in records" ng-bind="rec">
</li>
</div>
使用自定義過濾器。
angular.module('myApp', []);
var app= angular.module('myApp')
app.controller('MyController', MyController);
app.filter('split', function() {
return function(input, spliceplace) {
var spliceplace = spliceplace || ',';
return input.split(spliceplace);
}
});
function MyController($scope) {
$scope.records = "test,Test1,Test2,test3,test4";
};
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.10/angular.min.js"></script>
<div ng-app="myApp" ng-controller="MyController">
<ul>
<li ng-repeat="record in records | split">
<!-- OR <li ng-repeat="record in records | split:','">-->
{{record}}
</li>
</ul>
</div>
找到你的答案:
<body>
<div ng-app="App" ng-controller="mycontroller">
{{records}} <br/>
{{arrays}}<br />
<ul>
<li ng-repeat="array in arrays"> {{array}}</li>
</ul>
</div>
<script type="text/javascript">
var app = angular.module("App",[]);
app.controller("mycontroller",function($scope){
$scope.records = "test,Test1,Test2,Test3,Test4";
$scope. arrays = $scope.records.split(',');
})
</script>
使用angularJS的好方式配 –
歡迎@GangadharJannu –