ディレクティブの要素で Swipe.js を初期化しようとしています。以前はこれが機能していましたが、ディレクティブを変更して、カルーセルの種類に基づいてテンプレートを動的にロードし、コンパイルしてからプラグインを初期化しています。これは私の指示です:
directive('carousel', ['$compile', '$http', '$templateCache', function($compile, $http, $templateCache) {
var templateMap = {
default: 'default.html',
products: 'partials/carousel/products.html'
}, loader;
return {
restrict: 'E',
replace: true,
scope: {
type: '@',
slides: '='
},
compile: function(tElement, tAttrs) {
var template = templateMap[tAttrs.type];
loader = $http.get(template, {cache: false}).success(function(html) {
tElement.html(html);
});
return function(scope, element, attrs) {
loader.then(function() {
scope.$watch('slides', function(slides) {
if(slides) {
console.log(element);
template = angular.element($compile(tElement.html())(scope));
element.replaceWith(template);
console.log(element);
}
});
});
};
}
}
}])
期待どおりに要素をログconsole.log(element)
に記録すると。<carousel></carousel>
を実行するreplaceWith()
と、console.log(element)
ロードされた新しい置換要素が表示されることを期待していますが、それでもカルーセル要素がログに記録されます。
期待どおりに交換していた場合はSwipe(element)
、新しい要素で行いますが、明らかにそれは機能しません。
任意のヒント?