为我的应用程序添加过滤器时,为什么会出现错误?

时间:2013-08-07 11:21:48

标签: angularjs

我的Angular应用程序有这样的代码来添加服务:

stApp.factory('entityService', ['$http', '$q', '$resource', function (
                          $http, $q, $resource) {

现在我刚添加了一个这样的过滤器:

stApp.filter('truncate', function () {
    return function (value, wordwise, max, tail) {
        if (!value) return '';

当我调试时,我发现它在行stApp.filter中读取。

然而,当我运行我的代码时:

{{modal.data.text | trunacate:true:15:' ...'}}

我收到一条消息说:

Error: Unknown provider: trunacateFilterProvider <- trunacateFilter
at Error (<anonymous>)
at http://127.0.0.1:81/Scripts/angular.js:2714:19
at Object.getService [as get] (http://127.0.0.1:81/Scripts/angular.js:2840:39)
at http://127.0.0.1:81/Scripts/angular.js:2719:45
at Object.getService [as get] (http://127.0.0.1:81/Scripts/angular.js:2840:39)
at $get (http://127.0.0.1:81/Scripts/angular.js:10451:24)
at filter (http://127.0.0.1:81/Scripts/angular.js:6590:14)
at _filterChain (http://127.0.0.1:81/Scripts/angular.js:6581:41)
at statements (http://127.0.0.1:81/Scripts/angular.js:6557:25)
at parser (http://127.0.0.1:81/Scripts/angular.js:6484:13) 

有人能指出我正确的方向吗?我认为我的代码没问题,也无法理解为什么我收到这条消息。

1 个答案:

答案 0 :(得分:3)

拼写错误。

{{modal.data.text | trunacate:true:15:' ...'}}

应该是

{{modal.data.text | truncate:true:15:' ...'}}