Javascript TemplateUrl angularJS不工作
我对templateUrl有这样的问题 我的目录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',
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',