2014-10-08 63 views
0

我一直在寻找通过多个教程和其他堆栈溢出帖子没有成功为我的app.js $ routeProvider。这里是GitHub的链接项目https://github.com/StudentJoeyJMStudios/PetPinterest.git

这里是我的app.js

var app = angular.module('se165PetPinterestWebApp', [ 
    'ngAnimate', 
    'ngCookies', 
    'ngRoute' 
    ]); 

    app.config(['$routeProvider', function($routeProvider){ 
     $routeProvider.when('/select', 
      { 
       templateUrl: '/views/categorySelection.html', 
       controller: 'CatSelCtrl' 
      }). 
      otherwise(
      { 
       redirectTo: '/' 
      }); 
    }]); 

当我想要导航到新的页面我知道injuect $位置,并使用$位置相依操作路径,但代码它不会导航到新页面。以这种方式浏览页面是否会重新加载js文件,例如我的服务文件?请提前帮助谢谢你。

回答

1

你还记得在index.html中包含ng-view指令吗?

ngView是一个指令,通过将当前路径的渲染模板包含到主布局(index.html)文件中来补充$ route服务。每次当前路线改变时,包含的视图都会根据$ route服务的配置而变化。

https://docs.angularjs.org/api/ngRoute/directive/ngView

+0

我将它放入我的index.html只或每个HTML文件? – 2014-10-09 23:03:27

+0

是的,ng-view进入index.html;它定义了放置路由中定义的模板/视图的位置。 – Kokaubeam 2014-10-31 03:16:49

+0

那么只有在我的index.html文件中没有其他.html文件需要路由到? – 2014-12-05 19:27:04

相关问题