[英]angular ui-router state template not working
我使用ui-router創建了一個基本的角度應用程序。 我正在使用script標記從index.html提供部分模板,但出現此錯誤
Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:1337/home.html
這是我的代碼。
var app = angular.module('smApp', ['ui.router'])
.config(['$stateProvider', function ($stateProvider) {
$stateProvider
.state('home', {
url: '',
templateUrl: 'home.html',
controller: 'homeCtrl'
})
}])
.controller('homeCtrl', ['$scope', function ($scope) {
$scope.home = 1;
}]);
的index.html
<script type="text/script" id="home.html">
<div>Home Page {{home}}</div>
</script>
<body>
<div ui-view></div>
</body>
您需要更改包含模板代碼的腳本標簽的type屬性。 對於Angular,為了識別模板,您需要將type屬性從'text / script'更改為'text / ng-template'
您的index.html應該是
<script type="text/ng-template" id="home.html">
<div>Home Page {{home}}</div>
</script>
<div ui-view></div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.