2017-03-03 40 views

回答

0

您可以使用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>

0

使用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>

2

使用自定義過濾器。

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>

+0

使用angularJS的好方式配 –

+0

歡迎@GangadharJannu –

0

找到你的答案:

<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>