角度ui-路由器状态模板不工作

时间:2022-11-21 19:41:50

I created a basic angular app with ui-router. I am serving partial template from index.html with a script tag but I get this error

我用ui-路由器创建了一个基本的角应用。我正在从索引中提供部分模板。带有脚本标签的html,但是我得到了这个错误

Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:1337/home.html

Here is my code.

这是我的代码。

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

index . html

<script type="text/script" id="home.html">
    <div>Home Page {{home}}</div>
</script>
<body>
    <div ui-view></div>
</body>

1 个解决方案

#1


3  

You need to change type attribute of your script tag that contains template code. For Angular, in order to recognize the template, you need to change type attribute to 'text/ng-template' from 'text/script'

您需要更改包含模板代码的脚本标记的类型属性。对于角度,为了识别模板,您需要将type属性从“text/script”更改为“text/ng-template”

Your index.html should be

你的指数。html应该

<script type="text/ng-template" id="home.html">
    <div>Home Page {{home}}</div>
</script>
<div ui-view></div> 

#1


3  

You need to change type attribute of your script tag that contains template code. For Angular, in order to recognize the template, you need to change type attribute to 'text/ng-template' from 'text/script'

您需要更改包含模板代码的脚本标记的类型属性。对于角度,为了识别模板,您需要将type属性从“text/script”更改为“text/ng-template”

Your index.html should be

你的指数。html应该

<script type="text/ng-template" id="home.html">
    <div>Home Page {{home}}</div>
</script>
<div ui-view></div>