1

i am trying to inject a factory onto a controller using the angular fullstack generator and am having issues with the provider not found, where am i going wrong? i created an app with

npm install -g generator-angular-fullstack

yo angular-fullstack chatApp

yo angular:factory test

app/scripts/services/test.js

'use strict';

angular.module('chatApp')
.factory('test', function () {
// Service logic
// ...

 var meaningOfLife = 42;

 // Public API here
  return {
  someMethod: function () {
    return meaningOfLife;
  }
  };
  });

so where do i load the factory i am trying to load in the main.js file like so

app/scripts/controllers/main.js

'use strict';

angular.module('chatApp')
 .controller('MainCtrl', function ($scope, test) {
console.log(test);
   $scope.messages = 'this is a hardcoded test';
 });

app/scripts/main.js

'use strict';

angular.module('chatApp', [
'ngCookies',
'ngResource',
'ngSanitize',
'ngRoute',

])
.config(function ($routeProvider, $locationProvider, $httpProvider) {
 $routeProvider
  .when('/', {
    templateUrl: 'partials/main',
    controller: 'MainCtrl'
  })
  .when('/login', {
    templateUrl: 'partials/login',
    controller: 'LoginCtrl'
  })
  .when('/signup', {
    templateUrl: 'partials/signup',
    controller: 'SignupCtrl'
  })
  .when('/settings', {
    templateUrl: 'partials/settings',
    controller: 'SettingsCtrl',
    authenticate: true
  })
  .when('/about', {
    templateUrl: 'partials/about',
    controller: 'SettingsCtrl'
  })
  .otherwise({
    redirectTo: '/'
  });

 $locationProvider.html5Mode(true);

 // Intercept 401s and redirect you to login
 $httpProvider.interceptors.push(['$q', '$location', function($q, $location) {
  return {
    'responseError': function(response) {
      if(response.status === 401) {
        $location.path('/login');
        return $q.reject(response);
      }
      else {
        return $q.reject(response);
      }
    }
   };
   }]);
 })
.run(function ($rootScope, $location, Auth) {

 // Redirect to login if route requires auth and you're not logged in
 $rootScope.$on('$routeChangeStart', function (event, next) {

  if (next.authenticate && !Auth.isLoggedIn()) {
    $location.path('/login');
  }
  });

  console.log($location);

});

Error is:

304 Not Modified
    14ms    
angular.js (line 7997)

Error: [$injector:unpr] Unknown provider: testProvider <- test
http://errors.angularjs.org/1.2.11/$injector/unpr?p0=testProvider%20%3C-%20test
minErr/<@http://localhost:9000/bower_components/angular/angular.js:78
createInjector/providerCache.$injector<@http://localhost:9000/bower_components/angular/angular.js:3543
getService@http://localhost:9000/bower_components/angular/angular.js:3670
createInjector/instanceCache.$injector<@http://localhost:9000/bower_components/angular/angular.js:3548
getService@http://localhost:9000/bower_components/angular/angular.js:3670
invoke@http://localhost:9000/bower_components/angular/angular.js:3697
instantiate@http://localhost:9000/bower_components/angular/angular.js:3718
@http://localhost:9000/bower_components/angular/angular.js:6777
ngViewFillContentFactory/<.link@http://localhost:9000/bower_components/angular-route/angular-route.js:907
nodeLinkFn@http://localhost:9000/bower_components/angular/angular.js:6228
compositeLinkFn@http://localhost:9000/bower_components/angular/angular.js:5637
publicLinkFn@http://localhost:9000/bower_components/angular/angular.js:5542
boundTranscludeFn@http://localhost:9000/bower_components/angular/angular.js:5656
controllersBoundTransclude@http://localhost:9000/bower_components/angular/angular.js:6248
update@http://localhost:9000/bower_components/angular-route/angular-route.js:865
Scope.prototype.$broadcast@http://localhost:9000/bower_components/angular/angular.js:12245
2
  • seems as if the test.js is not being loaded, but i dont know how to make it load
    – mithereal
    Feb 25, 2014 at 5:27
  • seems as if the service script isnt being included into the main view file how do i make grunt include newly gcreated directives,services, etc into the main application and thus be available (seems as if the test.js is not being loaded, but i dont know how to make it load, you can see in the link at the bottom how the test.js isnt there but user.js is Heres a link to the app
    – mithereal
    Feb 25, 2014 at 5:39

1 Answer 1

0

i solved this i was using thw wrong generator h the correct one is yo angular-fullstack:factory test there is no yo remove function so you must manually remove created .js files and what was injected into main.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.