AngularJS中未知的ENV提供程序 [英] Unknown ENV provider in AngularJS

查看:38
本文介绍了AngularJS中未知的ENV提供程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用

I writing one constant file with Reff, I getting the follwing Exception If I tried like that :

angular.min.js:118 Error: [$injector:unpr] http://errors.angularjs.org/1.5.8/$injector/unpr?p0=ENVProvider%20%3C-%20ENV%20%3C-%20viewRoleController

我在控制台中收到上述错误:我的代码如下,

I get the error above in console: My code as follows,

jsp:-包含恒定文件位置

angularController

var app = angular.module('App', ['angularUtils.directives.dirPagination','ui.bootstrap']);

app.controller('viewRoleController', function($scope, $http, ENV, viewRoleService) {

    var dynamicData;

    $http.get('js/commons/AngularConstantFile.js').then(function (response) {
        dynamicData = response.data;
    });
});

常量文件:-

var app = angular.module('App');

app.constant("ENV", {
  "status412": "412",
  "Success": "Success",
});

推荐答案

在此简单的演示小提琴中尝试一下.确保您的配置在主应用程序加载到DOM之后加载,并且一切都会好起来.

Try it like in this simple demo fiddle. Ensure your config is loaded after your main application into DOM and you will be fine.

var myApp = angular.module('myApp',[]);

myApp.controller('MyCtrl', function ($scope, ENV) {
    $scope.ENV = ENV;
})

myApp.constant("ENV", {
  "status412": "412",
  "Success": "Success",
});


另一种方法是像在 demo小提琴一样,在自己的模块中创建配置并将其解析到您的主应用程序中.如果将您的配置外包到自己的文件中,这也将起作用.


An other approach is do create your config in an own module and parse it into your main application like in this demo fiddle. This will also work if your config is outsourced into an own file.

var config = angular.module('config',[]).constant("ENV", {
  "status412": "412",
  "Success": "Success",
});

var myApp = angular.module('myApp', ['config']);

myApp.controller('MyCtrl', function ($scope, ENV) {
    $scope.ENV = ENV;
});

这篇关于AngularJS中未知的ENV提供程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆