2017-05-03 7 views
2

私は以下の簡単なコードをCoffeescriptで持っています。

newScope = $rootScope.$new() 
newScope.test = "test" 
template = angular.element('<my-thing></my-thing>') 
linkFn = $compile(template) 
element = linkFn(newScope) 
angular.element("#thingContainer").html('').append(element) 

私の事はスコープとしてテスト変数を使用し、bindToControllerを持っている...

controller: MyThingController 
controllerAs: 'mtc' 
bindToController: true 
$scope: 
    test: "=" 

そして私は、私は希望bindToControllerを持っているので、私のコントローラは、この

class MyThingController 
    constructor: ($scope) -> 
    console.log($scope.test) 
    console.log(this.test) 

のように見えますthis.testが正しく解決され、$ scope.testが未定義であると予想しますが、正反対です。

私の質問は、$ compileを使用しているときでもコントローラにバインドされた$スコープをどうやって渡すのですか?

答えて

0

コンストラクタの代わりに$onInitにする必要がありました。

関連する問題