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

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

问题描述

所以我试图在我的指令中加载模板。该指令是可重用的。但我无法加载模板。我有其他模板加载并正常工作。

So I am trying to load the template in my directive. This directive is reusable. But I am failing to load the template. I have had other templates which are loaded and work properly.

我得到的错误是:

GET /ClassificationToolkitForGrails/classificationviewer.html 404 (Not Found) angular.js:8521
Error: [$compile:tpload] Failed to load template: classificationviewer.html

包含指令的 javascript 文件:

/**
 * 
 */
var classificationViewModule = angular.module('ald.classificationview',[]);

classificationViewModule.factory('classificationAPI',function(){
    return {
        getClassification:function($http, artifactId){
            //TODO add URL
            var url = "/Classification/getInfo?artifactId="+artifactId
            return $http({
                method: 'GET',
                url: url
            });
        }
    };
});

/*classificationViewModule.controller('testclassification',['$scope','$http',function($scope,$http){
    $http.get("/Classification/getInfo?artifactId=6450").success(function(data){
        $scope.classification = data;       
    })
}]);*/

classificationViewModule.directive('classificationview', function () {
    return {
        restrict: 'EA',
        scope: {},
        replace: true,
        link: function ($scope, element, attributes) {

        },
        controller: function ($scope, $http, classificationAPI) {

            classificationAPI.getClassification($http).success(function(data,status){               
                //TODO
                $scope.artifactClassification = data;
            }).error(function(data,status){
                if (404==status){
                    alert("no text");
                } else {
                    alert("bad stuff!");
                }
            });            
        },
        //TODO add template url
        templateUrl: "classificationviewer.html"
    };
});

模板文件:

<div>

Hello world

{{artifactClassification}}


</div>

index.html 文件:

<

!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta name="layout" content="main"/>
    <title>Classification Toolkit for Grails</title>
    <script type="text/javascript">
        angular.module('classtoolkitApp', [
            'ald.classificationview'
        ]).controller('index', function ($scope) {
        });
    </script>

    <asset:javascript src="ald/classificationview/classificationview.js"/>
</head>
<body >

<div ng-app="classtoolkitApp" ng-controller="index">   

    classification
    <classificationview artifactId=6450/>   

</div>

</body>
</html>


推荐答案

问题是由于某种原因你的http服务器可以在你的工作目录中找不到模板。

The problem is that for some reason your http server can't find template in your working directory.

你可以直接在浏览器中测试它:

You can test it directly in browser:

<url>/classificationviewer.html

你应该看到 404 NOT FOUND ,这意味着找不到这个模板。

And you should see 404 NOT FOUND, which means that this template was not found.

你说,你的其他模板工作得很好,所以你可以找到它们在工作目录中的位置,并将它放在同一个位置。

You said, that your other templates are working great, so you can find where are they located in your working directory and place this one at the same location.

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

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