且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

类型错误:无法读取的未定义的属性'templateUrl“

更新时间:2022-10-29 17:13:39

假设你的code被包裹在里面。

  myModule.config(['$ routeProvider',函数($ routeProvider){
  //你的code在这里
}]);

这应该工作。也许你可以显示什么路径到您的模板看起来像,因为它可能只是在路径中一个错字。

When I am trying to browse a url which is not in $routeProvider I am getting this error

TypeError: Cannot read property 'templateUrl' of undefined

here is the js code

$routeProvider
    .when('/', {
        templateUrl: '/MY/home/home',
        controller: function($scope) {
            //my custom code
        }
    })
    .otherwise({
        redirectTo: '/'
    });

assuming your code is wrapped inside

myModule.config(['$routeProvider', function($routeProvider) {
  //your code here
}]);

this should work. maybe you could show what the path to your template looks like because it might just be a typo in the path.