2014-09-15 7 views
6

तो मैं अपने निर्देश में टेम्पलेट लोड करने के लिए कोशिश कर रहा हूँ। यह निर्देश पुन: प्रयोज्य है। लेकिन मैं टेम्पलेट लोड करने में विफल रहा हूँ। मेरे पास अन्य टेम्पलेट्स हैं जो लोड होते हैं और ठीक से काम करते हैं।

त्रुटि है कि मैं हो रही है:

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

जावास्क्रिप्ट फ़ाइल निर्देश युक्त

/** 
* 
*/ 
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> 
+4

यह सच है कि लोड करने के लिए करने के लिए , आपको लगता है कि टेम्पलेट यूआरएल को आपके ऐप की जड़ से पथ चाहिए। – user2847643

+0

यकीन नहीं है कि मैं पालन करता हूं। तो टेम्पलेट एक प्लगइन में है जिसका उपयोग इस प्रोजेक्ट द्वारा किया जाता है। – krs

+0

हां और ध्यान दें कि कोणीय आपके वेबपैड की रूट पर .html फ़ाइल की खोज कर रहा है। यदि आपने कहीं फ़ोल्डर में प्लगइन रखा है तो आपको रूट से पूरा पथ निर्दिष्ट करने की आवश्यकता है। कहें /common/directives/someplugin/classificationviewer.html। – user2847643

उत्तर

3

समस्या यह है कि किसी कारण से आपका http सर्वर आपके काम कर निर्देशिका में टेम्पलेट नहीं मिल सका है।

आप इसे सीधे ब्राउज़र में परीक्षण कर सकते हैं:

<url>/classificationviewer.html 

और तुम 404 NOT FOUND देखना चाहिए, जिसका मतलब है कि इस टेम्पलेट नहीं मिला था।

तुमने कहा था, कि अपने अन्य टेम्पलेट्स महान काम कर रहे हैं, तो आप जहां वे अपने काम निर्देशिका में स्थित हैं खोजने के लिए और एक ही स्थान पर यह एक जगह कर सकते हैं।

2

के बाद संभव समाधान सही पथ के लिए 1. जांच कर रहे हैं। नेटवर्क टैब है कि क्या आप html फ़ाइल के लिए स्रोत टैब में 200 ठीक 2. जांच हो रही है की जाँच करें 3. यदि आप webpack उपयोग कर रहे हैं तो templateUrl बदल टेम्पलेट और प्रयोग की आवश्यकता होती है फ़ाइल

संबंधित मुद्दे