我在ng-repeat
完成後嘗試在Typescript中製作Angular指令時出現問題。ng-repeat後的Typescript中的Angular指令
這是我正在努力使該指令工作:
export interface ILightSliderInitDirectiveScope extends ng.IScope {
}
export class LightSliderInitDirective implements ng.IDirective {
public static DirectiveName: string = "lightSliderInit";
link = (scope: ILightSliderInitDirectiveScope, $element: any, attrs: ng.IAttributes) => {
if (scope.$watch('$scope.$last'))
scope.$emit('ngRepeatFinished');
}
}
在控制器我有這樣的方法:
_self.$scope.$on('ngRepeatFinished', function() {...});
,並在HTML:
<li ng-repeat="it in items" light-slider-init>...</li>
問題在於該指令有效,但它在的每次迭代中進入if條件210。
我該如何解決這個問題?
我不知道,你應該有任何「迭代」,可能與NG重複發生有關。它的所有元素都應該在單個摘要循環中呈現,因此對於任何正常使用,您應該將其視爲單個原子操作。你爲什麼要這個活動?你打算如何使用它? –
我想使用列表中的所有元素執行一個方法來使用lightslider插件。 http://sachinchoolur.github.io/lightslider/examples.html – Calde8
試試這個http://stackoverflow.com/a/30257914/1299394 –