未知提供者:uniqueFilterProvider < – uniqueFilter
这是我的技能
[[ skills ]]
结果
[{"id":17,"type":"Content Management","name":"NPM","value":"84","description":null,"img_path":null,"created_at":"2017-03-08 14:00:26","updated_at":"2017-03-09 15:25:50"},{"id":16,"type":"Content Management","name":"Composer ","value":"80","description":null,"img_path":null,"created_at":"2017-03-08 14:00:14","updated_at":"2017-03-09 13:16:54"},{"id":15,"type":"Framework","name":"AngularJS","value":"73","description":null,"img_path":null,"created_at":"2017-03-08 13:59:00","updated_at":"2017-03-08 13:59:30"},{"id":14,"type":"Content Management","name":"RequireJS","value":"65","description":null,"img_path":null,"created_at":"2017-03-08 13:58:06","updated_at":"2017-03-09 13:17:10"},{"id":9,"type":"Content Management","name":"Bower","value":"70","description":null,"img_path":null,"created_at":"2017-03-08 13:54:53","updated_at":"2017-03-09 13:17:02"},{"id":8,"type":"Web Scaffolding","name":"Yeoman","value":"50","description":null,"img_path":null,"created_at":"2017-03-08 13:54:43","updated_at":"2017-03-09 13:09:57"},{"id":7,"type":"Build System","name":"Gulp","value":"90","description":null,"img_path":null,"created_at":"2017-03-08 13:54:18","updated_at":"2017-03-09 13:07:20"},{"id":6,"type":"Development Environment","name":"Docker","value":"60","description":null,"img_path":null,"created_at":"2017-03-08 13:53:59","updated_at":"2017-03-09 14:15:38"},{"id":5,"type":"Development Environment","name":"Vagrant","value":"70","description":null,"img_path":null,"created_at":"2017-03-08 13:53:46","updated_at":"2017-03-08 13:53:46"},{"id":3,"type":"Build System","name":"Grunt ","value":"88","description":null,"img_path":null,"created_at":"2017-03-08 13:49:40","updated_at":"2017-03-09 12:01:04"},{"id":2,"type":"Server Management","name":"Linux","value":"87","description":null,"img_path":null,"created_at":"2017-03-08 13:45:34","updated_at":"2017-03-09 14:15:27"},{"id":1,"type":"Framework","name":"Laravel 5","value":"95","description":null,"img_path":null,"created_at":"2017-03-08 13:24:16","updated_at":"2017-03-09 14:15:14"}]
[[ skill.type ]]
结果
未知提供者:uniqueFilterProvider < – uniqueFilter
我已经把这些放在我的文件之上了,我的控制台上没有404,所以我假设,我正确地链接了它们。
对myApp
"use strict"; var myApp = angular.module('myApp', ['angular.filter','ui'], function($interpolateProvider,$httpProvider) { $interpolateProvider.startSymbol('[['); $interpolateProvider.endSymbol(']]'); //Setting headers $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8'; $httpProvider.defaults.headers.common['X-Requested-With'] = "XMLHttpRequest"; $httpProvider.defaults.headers.post['X-CSRF-TOKEN'] = $('meta[name=_token]').attr('content'); });
我还应该检查或研究什么?
我刚刚创建了这个工作演示。 看到这个 plunker。 您需要执行以下步骤才能使代码正常工作:html如下所示:
{{header}} {{item}}
script.js文件如下所示:
var myApp = angular.module('myApp', ['ui']) .controller('UniqueCtrl', function($scope){ $scope.header = "Unique Values"; $scope.items = ["obj","obj1","obj2","obj", "obj"]; });
关键点是:
-
将angular-ui.js添加到脚本部分。 你是rawgithub.com/angular-ui/angular-ui/master/build/angular-ui.js
-
您需要将其作为依赖项注入应用程序。 以下是您将如何做到这一点:
var myApp = angular.module(’myApp’,[‘ui’])
更新:
我将我的数组更改为一个对象数组,并使其处理数据。 这是我的傻瓜。 它提供您想要的输出:
这个问题中的所有filter都没有解决我的问题所以我不得不从官方的github doc复制filter。 然后按照上述问题的答案中的说明使用它
angular.module('yourAppNameHere').filter('unique', function () {
return函数(items,filterOn){
if (filterOn === false) { return items; } if ((filterOn || angular.isUndefined(filterOn)) && angular.isArray(items)) { var hashCheck = {}, newItems = []; var extractValueToCompare = function (item) { if (angular.isObject(item) && angular.isString(filterOn)) { return item[filterOn]; } else { return item; } }; angular.forEach(items, function (item) { var valueToCheck, isDuplicate = false; for (var i = 0; i < newItems.length; i++) { if (angular.equals(extractValueToCompare(newItems[i]), extractValueToCompare(item))) { isDuplicate = true; break; } } if (!isDuplicate) { newItems.push(item); } }); items = newItems; } return items; }; });