范围过滤器仅在第一个控制器中工作
Range filter works only in first controller
我有范围过滤器(下面的代码),它只适用于我的第一个控制器。我在其他控制器中以同样的方式在app.js和html中添加了这个过滤器,但不起作用,我不知道为什么?
在控制台中,我没有错误。
范围过滤器代码:
appPokayoke.filter('rangeFilter', function() {
return function(input, min, max) {
min = parseInt(min); //Make string input int
max = parseInt(max); //Make string input int
for (var i=min; i<max; i++)
input.push(i);
return input;
};
});
我的app.js文件:
(function(){
var appPokayoke = angular.module('appPokayoke', ['ngRoute', 'pyService']);
appPokayoke.config(['$routeProvider', function($routeProvider) {
code ...
}]);
appPokayoke.controller('DrawingsListCtrl', ['$scope', 'drawings', 'pantons', function ($scope, drawings, pantons) {
code ...
}]);
appPokayoke.controller('DrawingDetailsCtrl', ['$scope','drawings', 'articles', '$routeParams', 'articlesOfDrawings', 'pantonClass', function ($scope, drawings, articles, $routeParams, articlesOfDrawings, pantonClass, rangeFilter ) {
code ...
}]);
appPokayoke.controller('CreateArticleCtrl', ['$scope', '$http','pantons','$routeParams', 'articles', '$location', function ($scope, $http, pantons, $routeParams, articles, $location, rangeFilter) {
code ...
}]);
appPokayoke.controller('CreateArticleColorsCtr', ['$scope', '$http','$routeParams', 'articles', '$location', 'articlesOfDrawings', function ($scope, $http, $routeParams, articles, $location, articlesOfDrawings, rangeFilter ) {
code ...
}]);
appPokayoke.filter('rangeFilter', function() {
return function(input, min, max) {
min = parseInt(min); //Make string input int
max = parseInt(max); //Make string input int
for (var i=min; i<max; i++)
input.push(i);
return input;
};
});
})();
在html:中
<table class="table table-bordered table-hover table-striped">
<thead>
<tr>
<th width="7%">Lp.</th>
<th width="10%">Article <i class="fa fa-chevron-down"></i> </th>
<th width="10%">Colors in article</th>
<th ng-repeat="m in [] | rangeFilter:0:pyNumber track by $index">{{$index+1}}</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="article in articlesOfDrawings | filter : search track by $index">
<td>{{$index+1}}</td>
<td ng-repeat="column in article" style="background-color: rgb({{column[1]}});" ><p>{{ column[0] }}</p></td>
</tr>
</tbody>
</table>
编辑:过滤器不工作的控制器代码:appPokayoke.controller('CreateArticleColorsCtr',['$scope','$http','$souteParams','articles','s$location','articlesOfDrawing',函数($scope,$http,$routeParams,articles,$location,articlesOfGraphics,rangeFilter){
var drawingId = $routeParams.drawingId;
var pyNumber = $routeParams.pyNumber;
console.log(pyNumber);
$scope.rangeFilter = function(max) {
return max = pyNumber;
};
$scope.articleColors = {};
$scope.articleColorsData = {};
articles.getNewArticle(
$routeParams.articleName,
$routeParams.drawingId,
function (data) {
if(data !== '') {
$scope.articleColors = data;
}
else {
console.log('not ok articleColors');
}
}
);
articlesOfDrawings.getArticlesOfDrawings(
$routeParams.pyNumber,
$routeParams.drawingId,
function (data) {
if(data !== '') {
$scope.articlesOfDrawings = data;
}
else {
console.log('not ok articlesOfDrawings');
}
}
);
$scope.saveArticleColors = function (articleColorsData, success) {
success = success || function() {};
$http.post('api/admin/articles/save_colors/',
articleColorsData ).success(function (data){
console.log(data);
success(data.articleColorsData);
$scope.articleColorsData = articleColorsData;
console.log($scope.articleColorsData);
//$location.path('/drawings/'+ drawingId + '/' + pyNumber);
}).error(function (){
console.log('Problem ArticleColors');
});
}
}]);
将pyNumber放入您的作用域中,这样您就可以从过滤器中调用它,如下所示:
$scope.pyNumber = $routeParams.pyNumber;
console.log($scope.pyNumber);
// you don't need this function
// $scope.rangeFilter = function(max) {
// return max = pyNumber;
// };
相关文章:
- 为什么ng控制器不调用或工作或功能不工作
- AngularJS控制器不工作,为什么?(简单的控制器示例)
- 角度控制器功能赢得'不按指令工作
- console.log在角度控制器内不工作
- 角度控制器功能不;在指令内部调用时,似乎无法始终如一地工作
- 如何使Angular JS控制器与指令一起工作
- AngularApp中的多个控制器不工作
- 具有范围变量的控制器不工作
- 角度指令和属性Don'在控制器内创建和设置时无法工作
- AngularJS控制器没有'第一次刷新页面后无法工作
- 包含ngMock时控制器不工作
- 部分html视图's控制器未使用KendoPanelBar内容URL在指令模板URL中工作
- 在第三个控制器中使用时RootScope不工作
- angularJS-当我添加ngRoute时,控制器停止工作
- ng-显示无法从控制器工作
- extjs setLoading()不能从控制器工作
- 如何让这个AngularJS控制器工作($scope变量没有在控制器中初始化)
- NodeJS Express req.params,enrouten控制器工作不正常
- 我如何使ui-router控制器工作
- $emit from子控制器工作,但是$broadcast from父控制器不起作用