Custom Angular provider not working but no error
-
20-12-2019 - |
Question
I started a basic angular project using the yeoman angular generator.
I added very few things to the app:
angular.module('myApp', ['ui.router',
'ngAnimate',
'ngCookies',
'ngResource',
'ngSanitize',
'loginService',
'restangular']).
config(function($urlRouterProvider, $stateProvider) {
$urlRouterProvider.otherwise('/');
return $stateProvider.state('home', {
url: '/',
templateUrl: 'views/main.html',
controller: 'MainCtrl'
}).state('about', {
url: '/about',
templateUrl: 'views/about.html',
controller: 'AboutCtrl'
});
}).run(function($state) {
return $state.transitionTo('home');
});
loginService
is a custom Provider, and apparently it doesn't have any js error. I am loading it from index.html and apparently the browser console doesn't give me any error.
For sake of clarity I've taken the login-service from angular-login-example
The problem is that whenever I add this service to the app thigs stop to work and I don't get any error message. I did try to comment the dependency loginService
when I declare my app module but doesn't seems to help.
The only thing that makes the app work is to completely remove <script src="scripts/services/login-service.js"></script>
tag from the index.html
Maybe I do have a js error within it? But the browser's console seems happy tough.
EDIT: I generate my script from coffescript, maybe this could have something to do with it, I mean something happening during this conversion that I've missed? Here the login-services in coffeeScript and after the conversion in javascript
Solution
Your file starts with
angular.module('myApp', [])
By doing this, you redefine the module 'myApp', saying it has no dependency at all. What you want is to get a reference to the module 'myApp', not redefining it. You thus need
angular.module('myApp')