2016-08-22 2 views
0

内部スコープが破棄された後、そのスコープを再コンパイルしたいと思います。破壊後の角度範囲を復活させるには?

私は助けになるために再コンパイル機能を使用していますが、それは「継承」されています。 内部スコープを破棄したいときはいつでも、親スコープも破棄します。

この再コンパイル機能を変更しないで親スコープを削除しないでください。ここで

function compile() { 
     transclude(scope, function(clone, clonedScope) { 
      previousElements = clone; 
      $el.append(clone); 

      $timeout(function() { 

       scope.callBack(); 
    alert("Df"); 
}, 0); 
    }); 
    } 


$scope.callBack = function(){ 

     var elem = document.getElementById('test'); 
     //This code kill the test div, but also the parent scope 
     //Can i only kill the test div scope? 
    angular.element(elem).scope().$destroy(); 
    alert("dd"); 
} 

がplunkerです:あなたが実際に子スコープを作成することはありませんので、 http://plnkr.co/edit/MePu8BipkkdHV0IEatbo

+2

あなたが本当に作成した場合を除き、スコープを破壊しないでください。 –

+1

私はこれがあなたがしようとするものを達成する方法ではないと確信しています。あなたの目標は何ですか? –

答えて

0

それは、親スコープを破壊しています。

scope: truekcdRecompileディレクティブに追加できます。

app.directive('kcdRecompile', ['$parse','$timeout', function($parse, $timeout) { 
    'use strict'; 
    return { 
    transclude: true, 
    scope: true, 
    link: function link(scope, $el, attrs, ctrls, transclude) { 
... 

これは、kcdRecompileに独自の有効範囲を与えます。

あなたはkcdRecompileが親スコープを持っているが、そのトランスクルードコンテンツは独自のスコープを持ちたい場合は、あなたがscope.$new()代わりのscopeでトランスクルー関数を呼び出すことができます。

app.directive('kcdRecompile', ['$parse','$timeout', function($parse, $timeout) { 
    'use strict'; 
    return { 
    transclude: true, 
    link: function link(scope, $el, attrs, ctrls, transclude) { 
     var previousElements; 

     //compile(); 

     function compile() { 
     transclude(scope.$new(), function(clone, clonedScope) { 
... 
関連する問題