我試圖加載指令是有條件的模板,爲示例 -有條件裝載模板的角度指令
.directive('truncate',["$window", function($window, $compile){
return {
restrict: 'A',
templateUrl: 'template/truncate.html',
link: function (scope, element, attrs) {
var height = element[0].offsetHeight;
var shouldBetruncated = height>200;
if(shouldBetruncated){
// want my template to load here, otherwise template is not loaded
};
}
}
}])
.run(function ($templateCache) {
$templateCache.put('template/truncate.html',
'template code'
);
})
反正是有達致這?
你爲什麼需要這個? –