angularjs 错误:[$compile:tpload] 无法加载模板 [英] angularjs Error: [$compile:tpload] Failed to load template

查看:59
本文介绍了angularjs 错误:[$compile:tpload] 无法加载模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 angularjs 中构建简单的路由应用程序.我有带有 ng-view div 和用于路由的 javascript 代码的主 index.html 页面.还有2个简单的html页面view2.html和view3.html放在子文件夹partials1中.我得到低于错误.请帮忙.

错误:访问被拒绝.错误:[$compile:tpload] 无法加载模板:partials1/view3.htmlhttp://errors.angularjs.org/1.3.15/$compile/tpload?p0=partials1%2Fview3.html

  • index.html:

    <script src="angular.js"></script><script src="angular-route.js"></script><script type="text/javascript">var demoApp = angular.module('demoApp', ['ngRoute']);demoApp.controller('SimpleController', function($scope) {$scope.customers = [ {姓名:'乔恩史密斯1',城市:'夏洛特'}, {name : 'John Doe',城市:'纽约'}, {姓名 : '简·多伊',城市:'杰克逊维尔'}];});demoApp.config([ '$routeProvider', function($routeProvider) {$routeProvider.when('/view1', {templateUrl : 'partials1/view3.html',控制器:'简单控制器'}).when('/view2', {templateUrl : 'partials1/view2.html',控制器:'简单控制器'}).除此以外({重定向到:'/view1'});}]);

  • view2.html

    333333333333333

  • view3.html

    333333333333333

解决方案

Error: Access is denied 告诉您模板不可访问.尝试在浏览器中打开模板.像这样:http://my_project/partials1/view3.html.要查看您的应用使用的完整网址,请使用 dubug 控制台(XHR 选项卡).

I am trying to build simple routing app in angularjs. I have main index.html page with ng-view div and javascript code for routing. Also 2 simple html pages view2.html and view3.html placed in sub folder partials1. I am getting below error. Please help.

Error: Access is denied. Error: [$compile:tpload] Failed to load template: partials1/view3.html http://errors.angularjs.org/1.3.15/$compile/tpload?p0=partials1%2Fview3.html

  • index.html:

    <div data-ng-view></div>
    
    <script src="angular.js"></script>
    <script src="angular-route.js"></script>
    <script type="text/javascript">
        var demoApp = angular.module('demoApp', [ 'ngRoute' ]);
        demoApp.controller('SimpleController', function($scope) {
            $scope.customers = [ {
                name : 'Jon Smith1',
                city : 'Charlotte'
            }, {
                name : 'John Doe',
                city : 'New York'
            }, {
                name : 'Jane Doe',
                city : 'Jacksonville'
            } ];
        });
    
        demoApp.config([ '$routeProvider', function($routeProvider) {
            $routeProvider.when('/view1', {
                templateUrl : 'partials1/view3.html',
                controller : 'SimpleController'
            }).when('/view2', {
                templateUrl : 'partials1/view2.html',
                controller : 'SimpleController'
            }).otherwise({
                redirectTo : '/view1'
            });
        } ]);
    </script>
    

  • view2.html

    <div class="container">33333333333333</div>
    

  • view3.html

    <div class="container">33333333333333</div>
    

解决方案

Error: Access is denied tells you that the template is not accessible. Try to open the template in your browser. Something like this: http://my_project/partials1/view3.html. To see the full URL which is used by your app, use a dubug console (XHR tab).

这篇关于angularjs 错误:[$compile:tpload] 无法加载模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆