मुझे एक HTML-टेम्पलेट मिला है जो नियंत्रक की सरणी से डेटा लोड करता है और उन्हें एक तालिका में रखता है। इसके अलावा मेरे पास एक निर्देश है, जो तालिका पंक्तियों के लिए निष्कर्ष निकालता है। एपीआई अनुरोधों पर डेटा सरणी भर दी जा रही है। नए अनुरोधों के बाद मुझे अपने टेबल में अनुरोध परिणाम मिला है। पिछले परिणामों को साफ़ करने के बजाय प्रत्येक अनुरोध के लिए पंक्तियों का एक सेट जोड़ा जा रहा है।अनुरोध से पहले पिछले डेटा को साफ़ करें
मैंने अपने सरणी की स्थिति की जांच करने के लिए अपने नियंत्रक कोड पर डीबग किया है और इसे प्रत्येक अनुरोध से पहले साफ़ किया जा रहा है। वह पक्का है। हालांकि पिछले में नए परिणाम जोड़े गए हैं। मुझे लगता है कि कारण ट्रांसक्रिप्शन निर्देश के मेरे टेम्पलेट में हो सकता है।
टेम्पलेट लगता है:
angular.module('app').directive('myResult',
['$compile',
function ($compile) {
return {
transclude: true,
templateUrl: '/Scripts/app/templates/resultTemplate.html',
compile: function (tElement, tAttr, transclude) {
var contents = tElement.contents().remove();
var compiledContents;
return function (scope, iElement, iAttr) {
if (!compiledContents) {
compiledContents = $compile(contents, transclude);
}
compiledContents(scope, function (clone, scope) {
iElement.replaceWith(clone);
});
};
}
}
}]);
और अंत में टेम्पलेट ट्रांसक्लुजन के लिए इस्तेमाल किया:
<tr class="big-bord">
<td colspan="4"><h3>{{result.fullName}}</h3></td>
</tr>
<tr ng-repeat="item in result.items">
<td>{{item.value1}}</td>
<td>{{item.value2}}</td>
<td>{{item.value3}}</td>
<td>{{item.value4}}</td>
</tr>
मैं कैसे कर सकता है
<div class="row">
<div class="col-md-12">
<div id="results" ng-show="results.length > 0">
<table class="table result-table">
<thead>
<tr>
<th>1</th>
<th>2</th>
<th>3</th>
<th>4</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="result in results" my-result></tr>
</tbody>
</table>
</div>
</div>
</div>
यहाँ मेरी ट्रांसक्लुजन निर्देश का कोड है प्रत्येक एपीआई अनुरोध से पहले मेरे परिणाम साफ़ करें?
कोणीय का कौन सा संस्करण आप उपयोग कर रहे हैं? कोणीय 1.4 दस्तावेज़ों के अनुसार, संकलन (transclude) को बहिष्कृत कर दिया गया है। – jbrown
जब्रूउन, मैं कोणीय 1.5.7 का उपयोग करता हूं। स्थानांतरण के बजाय क्या आता है? – Waldemar
कोणीय दस्तावेज़ राज्य "इसके बजाय लिंक फ़ंक्शन पर पारित ट्रांज़ेक्शन फ़ंक्शन का उपयोग करें"। यहां और पढ़ें: https://docs.angularjs.org/api/ng/service/$compile – jbrown