由网友(9о後丶侽孓)分享简介:从后端,我得到一个字符串作为施工,适用 - 这意味着2个字一起From the back-end, I am getting a string as construction,apply - that means 2 words together.现在我需要将它们分解成2的话,我需要使用 NG-重复。我创建了一个...
从后端,我得到一个字符串作为施工,适用
- 这意味着2个字一起
From the back-end, I am getting a string as construction,apply
- that means 2 words together.
现在我需要将它们分解成2的话,我需要使用 NG-重复
。我创建了一个过滤器
来做到这一点。它分裂串入为2的长度,但如何在使用本 NG-重复
?
Now I need to break them into 2 words and I need to use the ng-repeat
. I created a filter
to do that. It splits the string into an array with a length of 2, but how to use this in ng-repeat
?
下面是我的code:
<div class="column design">
//app.Phase here is : `construction,apply`
<span ng-repeat="value in activeApp.Phase || commaBreak">{{$index}}</span> //instead of index i would like to show the word.
</div>
我的过滤器:
angular.module("tcpApp")
.filter("commaBreak",
function () {
return function (value) {
if (!value.length) return;
return value.split(',');
}
});
我在做什么错在这里?
What am I doing wrong here?
推荐答案
下面是:
var myApp = angular.module('myApp',[]);
myApp.controller('MyCtrl', ['$scope', function($scope) {
$scope.name = "construction,apply";
}]);
myApp.filter("commaBreak",
function () {
return function ( value ) {
if( !value.length ) return;
return value.split(',');
}
});
在HTML的一部分,你需要使用单个或
On html part you need to use the single OR.
<div ng-controller="MyCtrl">
<p ng-repeat="value in name | commaBreak">{{value}}</p>
</div>
下面是工作的例子: http://jsfiddle.net/HB7LU/16459/
相关推荐
最新文章