क्षमा करें दोस्तों अगर यह प्रश्न डुप्लिकेट है। मैं अभी भी वेब पर कोई उचित समाधान नहीं ढूंढ पाया, इसलिए मैं यहां पोस्ट कर रहा हूं।कोणीय 2 कॉल बाहरी जेएस फ़ाइल फंक्शन घटक के अंदर
मैं कोणीय 2 में एक घटक बना रहा हूं। मेरे पास बाहरी जेएस फ़ाइल है और इसे गतिशील रूप से लोड कर रहा है। बाहरी जेएस फ़ाइल में, मेरे पास पैरामीटर के साथ एक फ़ंक्शन है। मैं उस पैरामीटर को ngAfterViewInit
के अंदर कैसे कॉल कर सकता हूं। मैं कोणीय 2 करने के लिए नया हूँ, तो कैसे कोणीय 2 टाइपप्रति में js समारोह कॉल करने के लिए पता नहीं है, मैं आपके संदर्भ के लिए मेरी कोड पोस्ट करेंगे
app.component.ts
import { Component, OnInit, ElementRef,AfterViewInit } from '@angular/core';
declare var $:any;
@Component({
selector: 'app-root',
template: '<div></div>'
})
export class AppComponent implements AfterViewInit {
urlinput;
constructor(elRef: ElementRef){
this.urlinput = elRef.nativeElement.getAttribute('urlinput');
this.loadScript();
}
ngAfterViewInit() {
// need to call the js function here
//tried like this initializeDataTable(this.urlinput) not worked
}
loadScript() {
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = "app/Message.js";
head.appendChild(script);
}
}
Message.js (बाहरी जे एस फ़ाइल)
function initializeDataTable(dTableURL){
$.ajax({
"url": dTableURL,
"success": function(json) {
var tableHeaders;
$.each(json.columns, function(i, val){
tableHeaders += "<th>" + val + "</th>";
});
$("#tableDiv").empty();
$("#tableDiv").append('<table id="displayTable" class="display" cellspacing="0" width="100%"><thead><tr>' + tableHeaders + '</tr></thead></table>');
$('#displayTable').dataTable(json);
},
"dataType": "json"
});
}
index.html
<app-root urlinput="app/array.txt">Loading...</app-root>
कृपया इस समस्या को हल करने में मेरी मदद करें।
आप संपत्ति टाइपप्रति रास्ता के लिए मेरे कोड सही कृपया कर सकते हैं, मैं तुम्हें –
क्षमा काम नहीं –
सवाल लिंक जो आपके द्वारा दिया गया है प्राप्त करने में सक्षम नहीं हो सकता n प्रासंगिक नहीं है, यह दो .ts फ़ाइल से फ़ंक्शन आयात करना है, जो .js से .ts फ़ाइल में आयात नहीं है, उम्मीद है कि आप –