ajax呼び出しでオプションをテンプレートにロードする複数選択を表示するためのangularを使用したディレクティブを作成しようとしています。今のところ私の指示は次のとおりです。
function AngularMultiselect () {
return {
restrict: 'E',
replace: true,
templateUrl: 'temp.html',
scope: {
tipo: "@"
},
link: function(scope, element, attrs){
scope.open_tab = function(){
element.addClass('open');
$(document).on("click",function(){ //beign called at the same time
console.log("document clicked");
});
};
console.log('multiselect being called');
}
}
}
HTML:
<filtro tipo="client"></filtro>
テンプレート内:
<button type="button"
class="multiselect btn"
ng-click="open_tab()">
私が抱えている問題は、タブが同時に開閉することです。イベントを使用してイベントの伝播を停止しますが、送信できません...試しましたopen_tab($event)
が、$event
が含まれています'client'
。何か案は?
ここでそれが機能しているのを見ることができます:http://codepen.io/vandervals/pen/VeZrdV
この問題を回避するには、ドキュメントクリックハンドラの添付を延期するだけです。
の代わりに :
scope.open_tab = function(){
element.addClass('open');
$(document).on("click",function(){ //beign called at the same time
console.log("document clicked");
});
};
ただやる:
scope.open_tab = function(){
element.addClass('open');
$timeout(function() {
$(document).on("click",function(){ //no longer beign called at the same time
console.log("document clicked");
});
}, 1, false);
};
最初のクリックイベントを回避して2番目のハンドラーをトリガーするには
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加