AngularJS:[$编译:tpload]无法加载模板 [英] AngularJS: [$compile:tpload] Failed to load template

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

问题描述

我angularjs示例应用程序运行在我的NetBeans IDE精细基于本地服务器。但是,当我移动应用程序的nginx服务器它给了我下面的错误在浏览器中。

 错误:[$编译:tpload]无法加载模板:查看/ login.html的
http://errors.angularjs.org/1.3.15/$compile/tpload?p0=views%2Flogin.html
    在REGEX_STRING_REGEXP(angular.js:63)
    在调用HandleError(angular.js:16133)
    在processQueue(angular.js:13248)
    在angular.js:13264
    在范围$ get.Scope $的eval(angular.js:14466)。
    。在范围$ get.Scope $消化(angular.js:14282)
    。在范围$ get.Scope $申请(angular.js:14571)
    在完成(angular.js:9698)
    在completeRequest(angular.js:9888)
    在XMLHtt prequest.requestLoaded(angular.js:9829)

我的app.js

 的AppModule
        的.config(['$ routeProvider',函数($ routeProvider){
        $ routeProvider
                。什么时候('/',
                {
                    控制器:'LoginController中',
                    templateUrl:意见/ login.html的
                })
                。当('/主',
                {
                    控制器:'dashboardController',
                    templateUrl:意见/ dashboard.html
                })
                不然的话({redirectTo:'/'});
    }])


解决方案

我来找出我的问题是关于默认$ HTTP标头。我最近刚刚增加了一个默认的标题为授权和默认接受应用程序/ JSON

SURPRISE!事实证明,那些$ HTTP头不仅HTTP调用你对端点应用到$ ...而且要取得每一个电话,拉您的路由 HTML文件。而且因为如果使用这些头,整个事情失败的HTML文件就会爆炸。

My angularjs example app is running fine in my netbeans ide based local server. But when I moved the application to nginx server it gives me the following error in the browser.

Error: [$compile:tpload] Failed to load template: views/login.html
http://errors.angularjs.org/1.3.15/$compile/tpload?p0=views%2Flogin.html
    at REGEX_STRING_REGEXP (angular.js:63)
    at handleError (angular.js:16133)
    at processQueue (angular.js:13248)
    at angular.js:13264
    at Scope.$get.Scope.$eval (angular.js:14466)
    at Scope.$get.Scope.$digest (angular.js:14282)
    at Scope.$get.Scope.$apply (angular.js:14571)
    at done (angular.js:9698)
    at completeRequest (angular.js:9888)
    at XMLHttpRequest.requestLoaded (angular.js:9829)

My app.js

appModule
        .config(['$routeProvider', function($routeProvider) {
        $routeProvider
                .when('/',
                {
                    controller: 'loginController',
                    templateUrl: 'views/login.html'
                })
                .when('/main',
                {
                    controller: 'dashboardController',
                    templateUrl: 'views/dashboard.html'
                })
                .otherwise({redirectTo: '/'});
    }])

解决方案

I came to find out that my issue was regarding Default $http Headers. I had just recently added a default header for Authorization, and a default Accept for application/json.

SURPRISE!!! It turns out that those $http headers are NOT only applied to $http calls you make to your endpoints... but also to every call made that pulls your Routing html files. And since html files will explode if using those headers, the whole thing fails.

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

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