2016-03-31 4 views
0

私は、ディレクティブを動的にコンパイルしようとしています。このディレクティブは独立したスコープを持ちます。したがって、このような何か:ここディレクティブに分離スコープを挿入するにはどうすればよいですか?

angular.module('mod').directive 'foo', -> 
    restrict: 'E' 
    templateUrl: 'foo.html' 
    scope: 
     text: '=text' 
    bindToController: true 
    replace: true 
    controllerAs: 'fooCtrl' 
    controller: ($scope) -> 
     console.log @ # .text undefined 
     console.log $scope # .text undefined 
     return 

は、私がコンパイルする方法です:@がログに記録されたときに

template = "<foo></foo>" 
scope = $rootScope.$new() 
scope.text = "hello" 
$compile(template) scope, (clone, innerScope) -> 
    angular.element('body').append clone 

ただし、テキストがundefinedです。どのように私の指示にスコープを渡すことができますか?

答えて

0

リンクを使用してスコープにディレクティブを渡す方法は次のとおりです。

link: function (scope, element, attrs) { 
    scope.text = "hello"; 
} 
関連する問題