krs*_*krs 7 javascript templates angularjs
所以我试图在我的指令中加载模板.该指令是可重用的.但我无法加载模板.我有其他模板加载并正常工作.
我得到的错误是:
GET /ClassificationToolkitForGrails/classificationviewer.html 404 (Not Found) angular.js:8521
Error: [$compile:tpload] Failed to load template: classificationviewer.html
Run Code Online (Sandbox Code Playgroud)
包含指令的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"
};
});
Run Code Online (Sandbox Code Playgroud)
该模板文件:
<div>
Hello world
{{artifactClassification}}
</div>
Run Code Online (Sandbox Code Playgroud)
该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>
Run Code Online (Sandbox Code Playgroud)
小智 6
以下是可能的解决方案 1. 检查正确的路径。检查网络选项卡是否获得 200 OK 2. 检查 html 文件的源选项卡 3. 如果您使用的是 webpack,则将 templateUrl 更改为 template 并使用require加载文件
问题是由于某种原因你的 http 服务器无法在你的工作目录中找到模板。
可以直接在浏览器中测试:
<url>/classificationviewer.html
Run Code Online (Sandbox Code Playgroud)
您应该看到404 NOT FOUND,这意味着找不到该模板。
您说过,您的其他模板运行良好,因此您可以找到它们在工作目录中的位置,并将其放置在同一位置。
| 归档时间: |
|
| 查看次数: |
38541 次 |
| 最近记录: |