我有一種情況,當用戶點擊一個鏈接,我想自定義元素插入到DOM例如插入指令動態和編譯
//user clicks
$scope.click = function() {
var el = $compile("<my-directive></my-directive>")($scope);
$element.after(el);
};
的我的指令....指令具有HTML模板..比方說(template1.html)
<p>My Template for my-directive</p>
{{SomeProperty}}
我的指導性的定義如下
module.directive('myDirective', ['$compile', function ($compile) {
return {
restrict: 'E',
replace: true,
templateUrl: '/template1.html',
scope: true
};
}]);
如果我們假設myDirective中的範圍在運行此代碼後實際上具有SomeProperty的值,那麼確實將my-directive插入到DOM中並由模板替換 - template1.html,但{{SomeProperty}}尚未替換爲所有!我該怎麼做呢??
更多細節
嗯,你可以看看我的plunkr? http://plnkr.co/edit/5Qnv6i8jhyRwMEWtRQO7?p=preview – Paul 2014-09-25 05:01:31