1

Source: http://plnkr.co/edit/NpyTspWsY3rh0bzl9JUq

The code example works on plnkr. When I copy the code into a new app created with yeoman i get the following error:

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) 

I can't find out why it works on plnkr but doesn't work with a freshly created angular app.

The yeoman app looks like this:

'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);
    };
});

and it works in the yeoman scaffolded app when I change the code to this (return the say function in a object):

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);
    };
});
chriskohler
  • 155
  • 1
  • 9
  • it would be helpful if you placed the html and js code somewhere. My guess is that you are not including the `myHello` module when defining your app? `var app = angular.module('plunker', ['myHello']);` or you are not including '$hello' as a dependency to your filter/controller. – lucuma May 21 '13 at 15:44
  • Hi lucuma, there is a link to the plunkr at the top of the post. I also added the source of the yeoman app. As you can see, I injected the module myHello. Any idea? – chriskohler May 22 '13 at 06:19
  • Possible duplicate of [Angular "Unknown Provider" error after minification with Grunt Build in Yeoman app](http://stackoverflow.com/questions/20340644/angular-unknown-provider-error-after-minification-with-grunt-build-in-yeoman-a) – Paul Sweatte Dec 13 '15 at 18:52

0 Answers0