angular.js - angular1运行程序报错
问题描述
1.angular//运行程序报错Error: [$injector:unpr] Unknown provider: uniqueFilterProvider <- uniqueFilter2.相关代码

<!DOCTYPE html><html data-ng-app='sportsStore'><head> <meta charset='UTF-8'> <title>SportsStore</title><h3><strong>{{item.name}}</strong><span class='pull-right label label-primary'>{{item.price|currency}}</span> </h3> <span>{{item.description}}</span></body></html>
customFilters.js
angular.module('customFilters',[]).filter('unique', function () { return function (data,propertyName) {if(angular.isArray(data)&&angular.isString(propertyName)){var results=[]; var keys={}; for (var i=0;i<data.length;i++){var val=data[i][propertyName];if(angular.isUndefined(keys[val])){ keys[val]=true; results.push(val)} } return results;}else { return data;} }})
angular.js - angular1运行程序报错
应该是过滤器的问题,我刚刚开始学,找不出哪里错了啊0 0大神在哪里
问题解答
回答1:
你的sportsStore有依赖注入customFilters吗?
或者你先把customFilters改成sportsStore尝试一下
回答2:
<script> angular.module('sportsStore', ['customFilters']);</script><script src='https://www.xxx.com/wenda/controllers/sportsStore.js'></script>
你是先创建sportsStore module的,后面再引入controllers/sportsStore.js,在sportsStore.js文件里面将angular.module('customFilters',[])修改为angular.module('customFilters'),因为sportsStore module已经创建好了,无需再重新创建
相关文章:

网公网安备