简体   繁体   English

为什么ngSanitize依赖关系会破坏我的应用程序?

[英]Why does an ngSanitize dependency break my app?

To whom it may concern , 可能与谁有关

In effort to bind some html, which, to note, will include angular directives, upon injecting an ngSanitize dependency, my app ceases to render. 为了绑定一些html(值得注意的是包括角度指令),在注入ngSanitize依赖项时,我的应用程序停止了渲染。 Any thoughts as to why this happens, and whether my code has any blatant issues? 关于这种情况为什么发生以及我的代码是否存在任何公然问题的想法?

TLDR: everything works fine until bring ngSanitize into the picture! TLDR:一切正常,直到将ngSanitize带入图片为止!

Working Controller : 工作控制器

angular.module('appName')
 .controller('DecksCtrl', function ($scope, Auth, $http) {. . .

Broken Controller : 控制器损坏

angular.module('appName', ['ngSanitize'])
 .controller('DecksCtrl', function ($scope, Auth, $http) {. . .

Console Errors : 控制台错误

Uncaught Error: [$injector:modulerr] Failed to instantiate module appName due to: Error: [$injector:unpr] Unknown provider: $stateProvider

Thank you 谢谢

Peter Ward 彼得·沃德

Your problem is misunderstanding the difference between a module declaration and a reference to an existing module. 您的问题是误解了模块declaration和对现有模块的reference之间的区别。

To declare a module there are 2 arguments, the name and the dependency array 要声明一个模块,有两个参数,即名称和依赖项数组

angular.module('appName', [/* all the dependencies for this module*/]);

Then when you add components you use the module reference getter that does not have second dependency argument. 然后,当您添加组件时,将使用没有第二个依赖项参数的模块引用getter。 This getter returns the module object for chaining the component(s) to 此getter返回用于将组件链接到的模块对象

angular.module('appName')
 .controller('DecksCtrl', function ($scope, Auth, $http) {. . .

What you have done is try to inject a dependency into a module reference getter. 您要做的是尝试将依赖项注入模块引用getter中。 this in turn over wrote the original declaration for that module 这反过来写了该模块的原始声明

You want to inject it in your app.js . 您想将其注入到app.js In that yeoman generator its - appName / client / app / app.js 在那个yeoman生成器中-appName / client / app / app.js

angular.module('yourapp', [
  //your injections here
 'ngSanitize',
 'other injection',
 'another injection'

]).config(function ($routeProvider, $locationProvider, $httpProvider) {

You declare all of your apps dependancies here. 您在此处声明所有应用程序相关性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM