[英]How import and use method from outer js-file into AngularJS?
我想使用此文件中的功能https://ahunter.ru/js/min/ahunter_suggest.js
文檔說1.導入文件
<head>
...
<script src="path_to_scripts/jquery.min.js"></script>
<script src="path_to_scripts/ahunter_suggest.js"></script>
...
</head>
<div>
<input id="js-AddressField" placeholder="Введите адрес">
</div>
<script>
var options = { id : 'js-AddressField' };
AhunterSuggest.Address.Solid( options );
</script>
我將文件添加到項目目錄中,並在index.html中添加了鏈接,但無法調用AhunterSuggest.Address.Solid( options );
在我的控制器之一中。
怎么做對?
在您的AngularJS控制器中,您有一種初始化控制器的方法嗎? 如果是這樣,您必須調用第三方庫初始化程序(消息中的第三代碼)
確保在dom准備好並啟動angularJS控制器后調用此函數。
您之前的角度控制器(atm)
init() {
this.xxx()
}
Angular Controller之后:(應該是這樣)
init() {
this.xxx()
this.initialiseAHunterSuggest()
}
initialiseAHunterSuggest() {
var options = { id : 'js-AddressField' }
AhunterSuggest.Address.Solid( options )
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.