Angularjs 如何将隔离范围注入指令?

Angularjs 如何将隔离范围注入指令?,angularjs,Angularjs,我正在尝试动态编译一个指令。此指令具有隔离作用域。比如说: angular.module('mod').directive 'foo', -> restrict: 'E' templateUrl: 'foo.html' scope: text: '=text' bindToController: true replace: true controllerAs: 'fooCtrl' controller: ($scope

我正在尝试动态编译一个指令。此指令具有隔离作用域。比如说:

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
template=“”
scope=$rootScope.$new()
scope.text=“你好”
$compile(模板)作用域(克隆,内部作用域)->
angular.element('body')。追加克隆

但是,当记录
@
时,文本是
未定义的
。如何将范围传递到指令中?

以下是如何使用链接将范围传递到指令中

link: function (scope, element, attrs) {
  scope.text = "hello";
}