热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

未知提供程序:带有requires.js的ngMessagesProvider-Unknownprovider:ngMessagesProviderwithrequire.js

IamtryingtousengMessagesinmycontroller:我试图在我的控制器中使用ngMessages:Iamsettingupmyrequire.

I am trying to use ngMessages in my controller:

我试图在我的控制器中使用ngMessages:

I am setting up my require.js config:

我正在设定我的要求。js配置:

require({

  // libraries dependencies (fallback support)
  paths: {

    jquery: [
      'vendor/jquery/2.1.3/jquery.min'
    ],

    bootstrap: [
      'vendor/bootstrap/3.3.2/js/bootstrap.min'
    ],

    angular: [
      'vendor/angular.js/1.3.11/angular.min'
    ],

    angularResource: [
      'vendor/angular.js/1.3.11/angular-resource.min'
    ],

    angularAnimate: [
      'vendor/angular.js/1.3.11/angular-animate.min'
    ],

    ngMessages: [
      'vendor/angular.js/1.3.11/angular-messages.min'
    ],

    uiBootstrap: [
      'vendor/angular-ui/bootstrap/0.12.0/ui-bootstrap-tpls.min'
    ],

    uiRouter: [
      'vendor/angular-ui/ui-router/0.2.13/angular-ui-router.min'
    ],



  },

  // define js scripts dependencies
  shim: {

    'bootstrap': {
      deps: ['jquery']
    },

    'angular': {
      deps: ['bootstrap'],
      exports: 'angular'
    },

    'angularResource': {
      deps: ['angular']
    },

    'angularAnimate': {
      deps: ['angular']
    },

    'ngMessages': {
      deps: ['angular']
    },

    'uiBootstrap': {
      deps: ['bootstrap',  'angular']
    },

    'uiRouter': {
      deps: ['angular']
    },


  },

  priority: [
    'angular'
  ],

  deps: ['./ng.app']

});

and in module.js I am requiring ngMessages:

和模块。我需要ngMessages:

define(function(require) {
  'use strict';

  var angular = require('angular');
  require('angularResource');
  require('ngMessages');

  require('uiRouter');
  require('uiBootstrap');

  // angular module definition
  return angular.module(
    // module name
    'companies',

    // module dependencies
    [
      'ngResource',
      'ngMessages',

      'ui.router',
      'ui.bootstrap',

      require('shared/fend/input-utils/package').name,
      require('shared/fend/pagination/package').name
    ]
  );

});

and then in my controller I am trying to inject ngMessages:

然后在我的控制器中,我试图注入ngMessages:

define(function(require) {
  'use strict';

  var module = require('../module');
  require('../resources/rest');


  module.controller('CompaniesNewCtrl', CompaniesNewCtrl);


  CompaniesNewCtrl.$inject = [
    '$rootScope', '$scope', '$state',
    'CompaniesResource',
    'InputFocusFactory', 'ngMessages'
  ];

  function CompaniesNewCtrl($rootScope, $scope, $state, resource, input, ngMessages) {... })

but i am getting error:

但我犯了一个错误:

Error: $injector:unpr Unknown Provider Unknown provider: ngMessagesProvider

错误:$injector:unpr未知提供者未知提供者:ngMessagesProvider

What am I doing wrong?

我做错了什么?

1 个解决方案

#1


3  

Check API of ngMessages It is directive, not an provider so you can not inject it as dependency in component of angular. You can use it on html as AE (attribute/element)

检查ngmessage的API它是指令的,而不是提供程序,因此您不能将它作为依赖项注入到角度的组件中。您可以将其作为AE(属性/元素)在html中使用

API

API

.directive('ngMessages', ['$animate', function($animate) {
 var ACTIVE_CLASS = 'ng-active';
 var INACTIVE_CLASS = 'ng-inactive';

 return {
   require: 'ngMessages',
   restrict: 'AE',
   controller: ['$element', '$scope', '$attrs', function($element, $scope, $attrs) {
     //.......code here

推荐阅读
author-avatar
卢军好2602912493
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有