Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用yeoman模板时未定义AngularJs提供程序_Angularjs_Yeoman - Fatal编程技术网

使用yeoman模板时未定义AngularJs提供程序

使用yeoman模板时未定义AngularJs提供程序,angularjs,yeoman,Angularjs,Yeoman,资料来源: 代码示例在plnkr上工作。当我将代码复制到使用yeoman创建的新应用程序中时,出现以下错误: ReferenceError: $hello is not defined at $get (http://localhost:9000/scripts/app.js:21:16) at Object.invoke (http://localhost:9000/components/angular/angular.js:2864:28) at http://localhost:9000/

资料来源:

代码示例在plnkr上工作。当我将代码复制到使用yeoman创建的新应用程序中时,出现以下错误:

ReferenceError: $hello is not defined
at $get (http://localhost:9000/scripts/app.js:21:16)
at Object.invoke (http://localhost:9000/components/angular/angular.js:2864:28)
at http://localhost:9000/components/angular/angular.js:2702:37
at getService (http://localhost:9000/components/angular/angular.js:2824:39)
at Object.invoke (http://localhost:9000/components/angular/angular.js:2842:13)
at http://localhost:9000/components/angular/angular.js:2702:37
at Object.getService [as get] (http://localhost:9000/components/angular/angular.js:2824:39)
at http://localhost:9000/components/angular/angular.js:9545:24
at filter (http://localhost:9000/components/angular/angular.js:6107:14)
at _filterChain (http://localhost:9000/components/angular/angular.js:6098:41) 
我不知道为什么它可以在plnkr上运行,但不能在新创建的angular应用程序上运行

yeoman应用程序如下所示:

'use strict';

angular.module('asdfApp', ['myHello'])
  .config(function ($routeProvider) {
    $routeProvider
      .when('/', {
        templateUrl: 'views/main.html',
        controller: 'MainCtrl'
      })
      .otherwise({
        redirectTo: '/'
      });
  });



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

myModule.provider('$hello', function () {
    this.$get = function () {
        $hello = function (key) {
            return 'hello ' + key;
        };

        return $hello;
    }
});

myModule.filter('hello',function ($parse, $hello) {
    return function (key) {
        return $hello(key);
    };
});
当我将代码更改为返回对象中的say函数时,它在yeoman脚手架应用程序中起作用:

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

myModule.provider('$hello', function () {
    this.$get = function () {
        var say = function (key) {
            return 'hello ' + key;
        };

        return { say : say};
    }
});

myModule.filter('hello',function ($parse, $hello) {
    return function (key) {
        return $hello.say(key);
    };
});

如果您将html和js代码放在某个地方,这会很有帮助。我猜您在定义应用程序时没有包含myHello模块?var-app=angular.module'plunker',['myHello'];或者您没有将“$hello”作为过滤器/控制器的依赖项。嗨,lucuma,在文章的顶部有一个指向plunkr的链接。我还添加了yeoman应用程序的源代码。如您所见,我注入了模块myHello。有什么想法吗?可能是