注入sanitize依赖项时出错[$ injector:unpr]

时间:2016-09-05 20:31:44

标签: javascript angularjs asp.net-mvc twitter-bootstrap

我正在尝试使用AngularUIBootstrap中的(function () { var objectiveFactory = function ($http, animate) { debugger; return { getObjectives: function () { return $http.get('/api/Objective/'); } }; }; debugger; try { //objectiveFactory.$inject = ['$http', '$animate', '$sanitize'];// error objectiveFactory.$inject = ['$http', '$animate'];// no error angular.module('app', []).factory('objectiveFactory', objectiveFactory); } catch (e) {} }());

我有一个 objectFactory.js 文件:

$sanitize

这真的很奇怪,但是如果我添加新的依赖objectiveFactory.$inject = ['$http', '$animate', '$sanitize'];// not working

'$http'

然后我有一个错误:

  

angular.js:13920错误:[$ injector:unpr]   http://errors.angularjs.org/1.5.8/ $注射器/ unpr?P0 = sanitizeProvider%20%3 C-%20sanitize%20%3 C-%20objectiveController       在错误(本机)       在http://localhost:15533/Scripts/angular.min.js:6:412       在http://localhost:15533/Scripts/angular.min.js:43:174       在Object.d [as get]

'$animate',angular'js注射完全有效。

我已经探索了很多信息,并在我的Web API应用程序中仔细检查了以下建议:

  1. 我检查了angular-sanitize.js个版本的文件和1.5.8,它们是 bundles.Add(new ScriptBundle("~/bundles/angularjs").Include( "~/Scripts/jquery-1.10.2.min.js", "~/Scripts/bootstrap.min.js", "~/Scripts/angular.min.js", "~/Scripts/angular-animate.min.js", "~/Scripts/angular-sanitize.min.js", "~/Scripts/ui-bootstrap-tpls-2.1.3.js", "~/Scripts/objectiveFactory.js", "~/Scripts/objective.js" )); 相同的。

  2. 我的捆绑文件如下所示:

    objectiveController.$inject = ['$scope', '$http', 'objectiveFactory', '$animate', 'ngSanitize'];
    objectiveController.$inject = ['$scope', '$http', 'objectiveFactory', '$animate', '$sanitize'];
    objectiveController.$inject = ['$scope', '$http', 'objectiveFactory', '$animate', 'sanitize'];
    
  3. 我尝试了各种注射方法:

    '$http'
  4. 但是,错误是一样的:

      

    angular.js:13920错误:[$ injector:unpr]未知提供商:

    有人知道我做错了什么吗? ({{1}}注射完美有效)

1 个答案:

答案 0 :(得分:2)

ngSanitize 注入主模块以使用 $ sanitize ...

你也需要为$ animate做同样的事情,注入 ngAnimate