[英]AngularJS directive templateUrl not loading into view
所以我正在使用ui-view将我路由到局部视图。
//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的页面时,只能看到:
通用模拟
测试!!!!
所以我在这里做错了。 我检查了camelCasing,页面没有显示错误。 任何帮助将不胜感激!
更新:
我在chrome的开发工具中查看了网络调用。 正在加载Simulation.view.html,但不会加载tabs.view.html。
请求网址: http://sdc-stagt01/AngularJS/general-simulation/simulation.view.html请求方法:GET状态码:200 OK远程地址:10.19.8.96:80
文件子结构为:
/general-simulation/tabs/tabs.controller.js
/general-simulation/tabs/tabs.directives.js
/general-simulation/tabs/tabs.view.html /general-simulation/simulation.view.html
发表评论作为答案
将templateURL
更改为templateUrl
因此, entre的评论有很大帮助。 chrome开发人员开始吐出错误。
charlietfl在提到我的文件结构时也走了正确的路。 我需要将指令更改为如下形式:
templateUrl: 'general-simulation/tabs/tabs.view.html'
谢谢!
你这里有错字。 templateUrl
不是templateURL
function gsTabs () {
return {
restrict: "E",
templateURL: 'tabs.view.html' // change this to templateUrl
};
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.