简体   繁体   English

AngularJS指令templateUrl未加载到视图中

[英]AngularJS directive templateUrl not loading into view

So I am using ui-view to route me to a partial. 所以我正在使用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...>
    }
}
})();

The issue I am having is once it routes to 我遇到的问题是一旦路由到

// general-simulation/simulation.view.html

I'd like it to use a custom directive to insert more html into the page. 我希望它使用自定义指令在页面中插入更多html。 Inside simulation.view.html I have this. 在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>

The directive is constructed in 该指令在

// tabs.directives.js
(function(){
'use strict';

angular
    .module('app')
    .directive('gsTabs', gsTabs);

function gsTabs () {
    return {
        restrict: "E",
        templateURL: 'tabs.view.html'
    };
}

})();

Finally, my tabs.view.html looks like this. 最后,我的tabs.view.html看起来像这样。

<h1>YOU HAVE ENTERED TABS PARTIAL</h1>

When I navigate to the page that displays simulation.view all I can see is: 当我导航到显示Simulation.view的页面时,只能看到:

General Simulation 通用模拟

TEST!!!! 测试!!!!

So what am I doing wrong here. 所以我在这里做错了。 I checked for camelCasing and the page is not showing in errors. 我检查了camelCasing,页面没有显示错误。 Any help would be greatly appreciated! 任何帮助将不胜感激!

Update: 更新:

I viewed the network calls in chrome's dev tools. 我在chrome的开发工具中查看了网络调用。 simulation.view.html is being loaded but tabs.view.html isn't. 正在加载Simulation.view.html,但不会加载tabs.view.html。

Request URL: http://sdc-stagt01/AngularJS/general-simulation/simulation.view.html Request Method:GET Status Code:200 OK Remote Address:10.19.8.96:80 请求网址: http://sdc-stagt01/AngularJS/general-simulation/simulation.view.html请求方法:GET状态码:200 OK远程地址:10.19.8.96:80

The file substructure is: 文件子结构为:

/general-simulation/tabs/tabs.controller.js /general-simulation/tabs/tabs.controller.js
/general-simulation/tabs/tabs.directives.js /general-simulation/tabs/tabs.directives.js
/general-simulation/tabs/tabs.view.html /general-simulation/simulation.view.html /general-simulation/tabs/tabs.view.html /general-simulation/simulation.view.html

putting comment as answer 发表评论作为答案

change templateURL to templateUrl templateURL更改为templateUrl

So entre 's comment was a big help. 因此, entre的评论有很大帮助。 That got chrome dev to start spitting out errors. chrome开发人员开始吐出错误。

charlietfl Was on the right track with mentioning my file structure as well. charlietfl在提到我的文件结构时也走了正确的路。 I needed to change my directive to look like this: 我需要将指令更改为如下形式:

templateUrl: 'general-simulation/tabs/tabs.view.html'

Thank you! 谢谢!

You have a typo here. 你这里有错字。 templateUrl not templateURL templateUrl不是templateURL

function gsTabs () {
    return {
        restrict: "E",
        templateURL: 'tabs.view.html' // change this to templateUrl
    };
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM