Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript TemplateUrl angularJS不工作_Javascript_Angularjs_Templates_Directive - Fatal编程技术网

Javascript TemplateUrl angularJS不工作

Javascript TemplateUrl angularJS不工作,javascript,angularjs,templates,directive,Javascript,Angularjs,Templates,Directive,我对templateUrl有这样的问题 我的目录 myapp js home.js templates profile.html 我在home.js中尝试了这个 .state('app.profile', { url : '/profile', views : { 'appContent' : { templateUrl: '/templates/profile.html',

我对templateUrl有这样的问题 我的目录

myapp
    js
        home.js
    templates
        profile.html
我在home.js中尝试了这个

.state('app.profile', {
    url : '/profile',
    views : {
        'appContent' : {
            templateUrl: '/templates/profile.html',
            controller: 'ProfileController'
        }
    }
})
在我的profile.html中

<ion-view>
    <ion-content padding="true">
        <div>
            <p>My content</p>
        </div>
    </ion-content>
</ion-view> 
它不起作用,但当我尝试时

.state('app.profile', {
    url : '/profile',
    views : {
        'appContent' : {
            template: '<ion-view><ion-content padding="true"><div><p>My content</p></div></ion-content></ion-view>',
            controller: 'ProfileController'
        }
    }
})

它工作正常。发生了什么?如何修复它?

您只需删除额外的/before模板:

.state('app.profile', {
url : '/profile',
views : {
    'appContent' : {
        templateUrl: 'templates/profile.html',
        controller: 'ProfileController'
    }
}})

您可以在脚本顶部导入模板,并将其用作模板,而不是templateUrl:

import profile from '/templates/profile.html';
...

.state('app.profile', {
url : '/profile',
views : {
    'appContent' : {
        template: profile ,
        controller: 'ProfileController'
    }
  }
})

测试此项目时,浏览器中的url是什么样子的?尝试templateUrl:“../templates/profile.html”这很可能是母版页中的问题。仔细研究一下,你应该能够解决你的问题。试试templateUrl:'templates/profile.html',