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
です。どのように私の指示にスコープを渡すことができますか?