Angular module config not called

后端 未结 3 915
失恋的感觉
失恋的感觉 2020-12-29 04:48

I\'m trying to get my head around AngularJS and ran into a problem.

var myApp = angular.module(\'myApp\', [\'myApp.services\']);

myApp.config([\'$routeP         


        
相关标签:
3条回答
  • 2020-12-29 05:24

    I usually see routing applied by chaining them together:

    $routeProvider
        .when('/dashboard', {templateUrl: 'partial/dashboard', controller: DashboardController})
        .when('/menu', {templateUrl: 'partial/other', controller: OtherController})
        .otherwise({redirectTo: '/dashboard'});
    

    Can't see why yours would not work, but might be worth a go.

    0 讨论(0)
  • 2020-12-29 05:28

    It seems that the method I used for defining the service was overriding my myApp module.

    This is the overriding line

    angular.module('myApp', function ($provide) ...
    

    This code simply redefines the myApp module and adds a function to configure that one.


    I refactored service.js to this simplified version and it started to work.

    var myApp = angular.module('myApp');
    
    myApp.factory('securityService', function () {
        return SomeFancyServiceObject();
    });
    
    0 讨论(0)
  • 2020-12-29 05:31

    I was missing ng-app="myApp" inside my html tag - and I realized this while reading your question :-)

    0 讨论(0)
提交回复
热议问题