我有以下的angularjs指令,我希望能夠使用ng-click在屬性滑塊內執行showMap()。 HTML。我錯過了什麼?在angularjs指令的鏈接函數中存儲函數表達式並通過ng-click使用它
(function() {
'use strict';
angular
.module('myapp')
.directive('propertySlider', propertySlider);
function propertySlider($timeout) {
return {
restrict: 'E',
templateUrl: 'property-slider.html',
replace: true,
scope: {
property: '=',
photos: '='
},
link: function(scope, element) {
$timeout(function(){
var slider = element.flickity({
cellAlign: 'left',
cellSelector: '.gallery-cell',
lazyLoad: true,
wrapAround: true,
initialIndex: 1
});
var showMap = function(){
slider.flickity('select', 0);
};
},500);
}
};
}
})();
謝謝你的工作原理,除非如果我設置函數表達式$超時之外它執行時未定義。 – Gab
你的意思是什麼時候宣佈?什麼是錯誤? – charlietfl