0
我想在自定義事件上顯示引導彈出窗口(從服務器加載數據之後)。我不明白爲什麼這個代碼不起作用。 JSFiddle如何在自定義事件中顯示角度自舉彈出?
第二個問題,如果我設置replace = true
如何觸發事件?由於IE8不支持自定義標籤並拋出異常。
<div ng-app="tcApp">
<manual></manual>
</div>
var tcApp = angular.module('tcApp', [ 'ui.bootstrap' ]);
tcApp.config(function ($tooltipProvider) {
$tooltipProvider.setTriggers({
'openAfterLoad': 'closeOnClick'
});
});
tcApp.directive('manual', [ '$timeout', '$interval', function($timeout, $interval) {
return {
restrict: 'E',
scope: {},
template:
'<a ' +
' href="#" ' +
' ng-if="isManualVisible" ' +
' popover-append-to-body="true" ' +
' popover-placement="bottom" ' +
' popover-trigger="openAfterLoad" ' +
' popover-title="{{title}}" ' +
' popover="{{content}}" ' +
' tooltip="{{title}}" ' +
' >' +
' <span class="{{textClass}}">' +
' <span ng-show="!loading" class="glyphicon glyphicon-question-sign"></span>' +
' <span ng-show="loading" class="glyphicon glyphicon-refresh"></span>' +
' </span>' +
'</a>',
replace: false, // true for IE8 only
link: function (scope, element, attr) {
scope.isManualVisible = true;
scope.title = 'First title value';
scope.content = 'First content value';
scope.textClass = 'text-info';
scope.opened = false;
scope.loading = false;
scope.loaded = false;
scope.loadedTitle = false;
scope.loadedContent = false;
scope.checkLoadState = function() {
if (scope.loadedTitle && scope.loadedContent) {
scope.loaded = true;
if (scope.loading)
scope.loading = false;
element.triggerHandler('openAfterLoad');
}
};
scope.$watch('loadedTitle', scope.checkLoadState);
scope.$watch('loadedContent', scope.checkLoadState);
element.on('openAfterLoad', function(event) {
console.log('openAfterLoad');
scope.opened = true;
});
element.on('closeOnClick', function(event) {
console.log('closeOnClick');
scope.opened = false;
});
element.on('click', function(event) {
console.log('click');
if (scope.loaded) {
if (scope.opened)
element.triggerHandler('closeOnClick');
else
element.triggerHandler('openAfterLoad');
} else {
scope.loadData();
}
});
scope.loadData = function() {
if (!scope.loaded && !scope.loading) {
scope.loading = true;
$interval(function() {
scope.title = 'New title value';
scope.loadedTitle = true;
}, 5000, 1);
$interval(function() {
scope.content = 'New content value';
scope.loadedContent = true;
}, 5000, 1);
}
};
}
};
}]);
你的代碼是一個爛攤子,你是混合角和'replace' jQuery是過時了。並且您正在使用舊版本的'ui-bootstrap'。你有沒有嘗試過這些例子? – svarog
我需要使用ie8的舊版本。這是庫的最後一個版本,它仍然支持ie8。並且必須使用'replace = true'(ie8不支持自定義標籤並拋出異常)。我怎樣才能綁定事件處理程序和觸發事件的角度和沒有jQuery(即沒有混合)? –
使用內建的角度指令,'ng-click','ng-change'等。 – svarog