@@ -3899,8 +3899,8 @@ describe('$compile', function() {
38993899 'baz' : 'biz'
39003900 } ;
39013901 element = $compile ( '<div foo-dir dir-data="remoteData" ' +
3902- 'dir-str="Hello, {{whom}}!" ' +
3903- 'dir-fn="fn()"></div>' ) ( $rootScope ) ;
3902+ 'dir-str="Hello, {{whom}}!" ' +
3903+ 'dir-fn="fn()"></div>' ) ( $rootScope ) ;
39043904 $rootScope . $digest ( ) ;
39053905 expect ( controllerCalled ) . toBe ( true ) ;
39063906 } ) ;
@@ -3939,8 +3939,8 @@ describe('$compile', function() {
39393939 'baz' : 'biz'
39403940 } ;
39413941 element = $compile ( '<div foo-dir dir-data="remoteData" ' +
3942- 'dir-str="Hello, {{whom}}!" ' +
3943- 'dir-fn="fn()"></div>' ) ( $rootScope ) ;
3942+ 'dir-str="Hello, {{whom}}!" ' +
3943+ 'dir-fn="fn()"></div>' ) ( $rootScope ) ;
39443944 $rootScope . $digest ( ) ;
39453945 expect ( controllerCalled ) . toBe ( true ) ;
39463946 } ) ;
@@ -3972,6 +3972,114 @@ describe('$compile', function() {
39723972 expect ( childScope . theCtrl ) . toBe ( myCtrl ) ;
39733973 } ) ;
39743974 } ) ;
3975+
3976+
3977+ it ( 'should re-install controllerAs and bindings for returned value from controller (new scope)' , function ( ) {
3978+ var controllerCalled = false ;
3979+ var myCtrl ;
3980+
3981+ function MyCtrl ( ) {
3982+ }
3983+ MyCtrl . prototype . test = function ( ) {
3984+ expect ( this . data ) . toEqualData ( {
3985+ 'foo' : 'bar' ,
3986+ 'baz' : 'biz'
3987+ } ) ;
3988+ expect ( this . str ) . toBe ( 'Hello, world!' ) ;
3989+ expect ( this . fn ( ) ) . toBe ( 'called!' ) ;
3990+ } ;
3991+
3992+ module ( function ( $compileProvider , $controllerProvider ) {
3993+ $controllerProvider . register ( 'myCtrl' , function ( ) {
3994+ controllerCalled = true ;
3995+ myCtrl = this ;
3996+ return new MyCtrl ( ) ;
3997+ } ) ;
3998+ $compileProvider . directive ( 'fooDir' , valueFn ( {
3999+ templateUrl : 'test.html' ,
4000+ bindToController : {
4001+ 'data' : '=dirData' ,
4002+ 'str' : '@dirStr' ,
4003+ 'fn' : '&dirFn'
4004+ } ,
4005+ scope : true ,
4006+ controller : 'myCtrl as theCtrl'
4007+ } ) ) ;
4008+ } ) ;
4009+ inject ( function ( $compile , $rootScope , $templateCache ) {
4010+ $templateCache . put ( 'test.html' , '<p>isolate</p>' ) ;
4011+ $rootScope . fn = valueFn ( 'called!' ) ;
4012+ $rootScope . whom = 'world' ;
4013+ $rootScope . remoteData = {
4014+ 'foo' : 'bar' ,
4015+ 'baz' : 'biz'
4016+ } ;
4017+ element = $compile ( '<div foo-dir dir-data="remoteData" ' +
4018+ 'dir-str="Hello, {{whom}}!" ' +
4019+ 'dir-fn="fn()"></div>' ) ( $rootScope ) ;
4020+ $rootScope . $digest ( ) ;
4021+ expect ( controllerCalled ) . toBe ( true ) ;
4022+ var childScope = element . children ( ) . scope ( ) ;
4023+ expect ( childScope ) . not . toBe ( $rootScope ) ;
4024+ expect ( childScope . theCtrl ) . not . toBe ( myCtrl ) ;
4025+ expect ( childScope . theCtrl . constructor ) . toBe ( MyCtrl ) ;
4026+ childScope . theCtrl . test ( ) ;
4027+ } ) ;
4028+ } ) ;
4029+
4030+
4031+ it ( 'should re-install controllerAs and bindings for returned value from controller (isolate scope)' , function ( ) {
4032+ var controllerCalled = false ;
4033+ var myCtrl ;
4034+
4035+ function MyCtrl ( ) {
4036+ }
4037+ MyCtrl . prototype . test = function ( ) {
4038+ expect ( this . data ) . toEqualData ( {
4039+ 'foo' : 'bar' ,
4040+ 'baz' : 'biz'
4041+ } ) ;
4042+ expect ( this . str ) . toBe ( 'Hello, world!' ) ;
4043+ expect ( this . fn ( ) ) . toBe ( 'called!' ) ;
4044+ } ;
4045+
4046+ module ( function ( $compileProvider , $controllerProvider ) {
4047+ $controllerProvider . register ( 'myCtrl' , function ( ) {
4048+ controllerCalled = true ;
4049+ myCtrl = this ;
4050+ return new MyCtrl ( ) ;
4051+ } ) ;
4052+ $compileProvider . directive ( 'fooDir' , valueFn ( {
4053+ templateUrl : 'test.html' ,
4054+ bindToController : true ,
4055+ scope : {
4056+ 'data' : '=dirData' ,
4057+ 'str' : '@dirStr' ,
4058+ 'fn' : '&dirFn'
4059+ } ,
4060+ controller : 'myCtrl as theCtrl'
4061+ } ) ) ;
4062+ } ) ;
4063+ inject ( function ( $compile , $rootScope , $templateCache ) {
4064+ $templateCache . put ( 'test.html' , '<p>isolate</p>' ) ;
4065+ $rootScope . fn = valueFn ( 'called!' ) ;
4066+ $rootScope . whom = 'world' ;
4067+ $rootScope . remoteData = {
4068+ 'foo' : 'bar' ,
4069+ 'baz' : 'biz'
4070+ } ;
4071+ element = $compile ( '<div foo-dir dir-data="remoteData" ' +
4072+ 'dir-str="Hello, {{whom}}!" ' +
4073+ 'dir-fn="fn()"></div>' ) ( $rootScope ) ;
4074+ $rootScope . $digest ( ) ;
4075+ expect ( controllerCalled ) . toBe ( true ) ;
4076+ var childScope = element . children ( ) . scope ( ) ;
4077+ expect ( childScope ) . not . toBe ( $rootScope ) ;
4078+ expect ( childScope . theCtrl ) . not . toBe ( myCtrl ) ;
4079+ expect ( childScope . theCtrl . constructor ) . toBe ( MyCtrl ) ;
4080+ childScope . theCtrl . test ( ) ;
4081+ } ) ;
4082+ } ) ;
39754083 } ) ;
39764084
39774085
0 commit comments