Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.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 角度ui路由器状态模板不工作_Javascript_Angularjs_Templates_Angular Ui Router - Fatal编程技术网

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

Javascript 角度ui路由器状态模板不工作,javascript,angularjs,templates,angular-ui-router,Javascript,Angularjs,Templates,Angular Ui Router,我用ui路由器创建了一个基本的angular应用程序。我正在为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(['$s

我用ui路由器创建了一个基本的angular应用程序。我正在为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>

主页{{Home}

您需要更改包含模板代码的脚本标记的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> 

主页{{Home}