所以我使用ui-view来将我路由到部分。AngularJS指令templateUrl无法加载到视图中
//route.provider.js
(function() {
'use strict';
angular
.module('app')
.provider('RouteService', RouteService);
RouteService.$inject = ['$stateProvider', '$urlRouterProvider'];
function RouteService ($stateProvider, $urlRouterProvider) {
var service = {};
this.$get = function() { return service; };
this.initialize = function() {
$urlRouterProvider.otherwise('/login');
$stateProvider
.state('home', {
url: '/home',
controller: 'HomeController',
templateUrl: 'home/home.view.html',
controllerAs: 'viewModel'
})
.state('login', {
url: '/login',
controller: 'LoginController',
templateUrl: 'login/login.view.html',
controllerAs: 'viewModel'
})
//TODO Impliment the following partial pages...
.state('gensim', {
url: '/gensim',
templateUrl: 'general-simulation/simulation.view.html',
controller: 'TabsController',
controllerAs: 'tabs'
})
<...more routes...>
}
}
})();
我遇到的问题是,一旦其路由到
// general-simulation/simulation.view.html
我想它使用自定义指令插入更多的HTML到页面中。 在simulation.view.html里面我有这个。
<div class="container">
<div class="row center">
<div class="col-xs-12">
<h1>General Simulation</h1>
<gs-tabs><h1>TEST!!!!</h1></gs-tabs>
</div>
</div>
</div>
的指令在
// tabs.directives.js
(function(){
'use strict';
angular
.module('app')
.directive('gsTabs', gsTabs);
function gsTabs() {
return {
restrict: "E",
templateURL: 'tabs.view.html'
};
}
})();
最后,我tabs.view.html看起来是这样构成的。
<h1>YOU HAVE ENTERED TABS PARTIAL</h1>
当我浏览到一个显示页面simulation.view所有我能看到的是:
通用仿真
TEST !!!!
那么我在这里做错了什么。我检查了camelCasing,页面没有显示错误。任何帮助将不胜感激!
更新:
我认为在Chrome的开发工具的网络电话。 simulation.view.html正在加载,但tabs.view.html不是。
请求URL:http://sdc-stagt01/AngularJS/general-simulation/simulation.view.html 请求方法:GET 状态代码:200 OK 远程地址:10.19.8.96:80
文件子是:
/通用模拟/标签/ tabs.controller.js
/general-simulation/tabs/tabs.directives.js
/general-simulation/tabs/tabs.view.html /general-simulation/simulation.view.html
检查浏览器开发工具制作XHR请求,看是否正确的请求做出和它的状态和响应主体。似乎奇怪所有其他模板都在目录中,但'tabs'不是 – charlietfl
尝试使用'ng-include'而不是'gsTabs'指令,并且@charlietfl表示,检查您的模板路径 – rkalita
将'templateURL'更改为'templateUrl' – harishr