我爲自舉彈出窗口寫入了自定義指令,但遇到了一些麻煩。 這是代碼:引導彈出窗口的角度指令
angular.module('CommandCenterApp')
.directive('bzPopover', function($compile,$http, $commandHelper) {
return{
restrict: "A",
replace: false,
scope: {
currencies:"=data",
selected:"=selected"
},
link: function (scope, element, attrs) {
var html = '<div class="currency-popup">' +
'<span class="select-label">Select currency:</span>'+
'<select class="custom-select" ng-model="selected" ng-options="currency.CurrencyName for currency in currencies track by currency.CurrencyId">' +
'</select>' +
'<button class="btn btn-green" ng-click="saveCurrency()">Save</button>'+
'</div>';
var compiled = $compile(html)(scope);
$(element).popover({
content:compiled,
html: true,
placement:'bottom'
});
scope.saveCurrency = function() {
var obj = {
Currency:scope.selected,
venueId: $commandHelper.getVenueId()
}
$http.post("/api/currencyapi/changecurrency", obj).success(function() {
scope.$emit('currencySaved', scope.selected);
});
//$(element).popover('hide');
}
scope.$watch('selected', function() {
console.log(scope.selected);
});
}
}
});
當我第一次調用酥料餅的一切工作正常,我點擊按鈕,它觸發scope.saveChanges
功能。然後關閉popover並再次調用它,並且指令不再起作用。 在標記彈出現在爲:
<a bz-popover data="controller.currencies" selected="controller.selectedCurrency" class="change-currency hidden-xs hidden-sm" href>Change currency</a>
任何人都可以幫助我嗎?
更新:它看起來像所有綁定(scope.saveCurrency
,在選定的屬性上觀看)在popover hidding後停止工作。
請在Plunker中重新創建你的指令的工作場景。這有助於更快地找到解決方案。 –
嘗試明確定義一個'觸發器:'點擊''或將值改爲''焦點''或其他東西,看看它是否做了什麼。 'trigger'是一個像'replace','restrict'和'link'一樣返回的屬性。但如果不能在plnkr或jsfiddle中重現問題,就很難找出問題所在。 – UltraSonja