@@ -3910,8 +3910,8 @@ describe('$compile', function() {
3910
3910
'baz' : 'biz'
3911
3911
} ;
3912
3912
element = $compile ( '<div foo-dir dir-data="remoteData" ' +
3913
- 'dir-str="Hello, {{whom}}!" ' +
3914
- 'dir-fn="fn()"></div>' ) ( $rootScope ) ;
3913
+ 'dir-str="Hello, {{whom}}!" ' +
3914
+ 'dir-fn="fn()"></div>' ) ( $rootScope ) ;
3915
3915
$rootScope . $digest ( ) ;
3916
3916
expect ( controllerCalled ) . toBe ( true ) ;
3917
3917
} ) ;
@@ -3950,8 +3950,8 @@ describe('$compile', function() {
3950
3950
'baz' : 'biz'
3951
3951
} ;
3952
3952
element = $compile ( '<div foo-dir dir-data="remoteData" ' +
3953
- 'dir-str="Hello, {{whom}}!" ' +
3954
- 'dir-fn="fn()"></div>' ) ( $rootScope ) ;
3953
+ 'dir-str="Hello, {{whom}}!" ' +
3954
+ 'dir-fn="fn()"></div>' ) ( $rootScope ) ;
3955
3955
$rootScope . $digest ( ) ;
3956
3956
expect ( controllerCalled ) . toBe ( true ) ;
3957
3957
} ) ;
@@ -3983,6 +3983,114 @@ describe('$compile', function() {
3983
3983
expect ( childScope . theCtrl ) . toBe ( myCtrl ) ;
3984
3984
} ) ;
3985
3985
} ) ;
3986
+
3987
+
3988
+ it ( 'should re-install controllerAs and bindings for returned value from controller (new scope)' , function ( ) {
3989
+ var controllerCalled = false ;
3990
+ var myCtrl ;
3991
+
3992
+ function MyCtrl ( ) {
3993
+ }
3994
+ MyCtrl . prototype . test = function ( ) {
3995
+ expect ( this . data ) . toEqualData ( {
3996
+ 'foo' : 'bar' ,
3997
+ 'baz' : 'biz'
3998
+ } ) ;
3999
+ expect ( this . str ) . toBe ( 'Hello, world!' ) ;
4000
+ expect ( this . fn ( ) ) . toBe ( 'called!' ) ;
4001
+ }
4002
+
4003
+ module ( function ( $compileProvider , $controllerProvider ) {
4004
+ $controllerProvider . register ( 'myCtrl' , function ( ) {
4005
+ controllerCalled = true ;
4006
+ myCtrl = this ;
4007
+ return new MyCtrl ( ) ;
4008
+ } ) ;
4009
+ $compileProvider . directive ( 'fooDir' , valueFn ( {
4010
+ templateUrl : 'test.html' ,
4011
+ bindToController : {
4012
+ 'data' : '=dirData' ,
4013
+ 'str' : '@dirStr' ,
4014
+ 'fn' : '&dirFn'
4015
+ } ,
4016
+ scope : true ,
4017
+ controller : 'myCtrl as theCtrl'
4018
+ } ) ) ;
4019
+ } ) ;
4020
+ inject ( function ( $compile , $rootScope , $templateCache ) {
4021
+ $templateCache . put ( 'test.html' , '<p>isolate</p>' ) ;
4022
+ $rootScope . fn = valueFn ( 'called!' ) ;
4023
+ $rootScope . whom = 'world' ;
4024
+ $rootScope . remoteData = {
4025
+ 'foo' : 'bar' ,
4026
+ 'baz' : 'biz'
4027
+ } ;
4028
+ element = $compile ( '<div foo-dir dir-data="remoteData" ' +
4029
+ 'dir-str="Hello, {{whom}}!" ' +
4030
+ 'dir-fn="fn()"></div>' ) ( $rootScope ) ;
4031
+ $rootScope . $digest ( ) ;
4032
+ expect ( controllerCalled ) . toBe ( true ) ;
4033
+ var childScope = element . children ( ) . scope ( ) ;
4034
+ expect ( childScope ) . not . toBe ( $rootScope ) ;
4035
+ expect ( childScope . theCtrl ) . not . toBe ( myCtrl ) ;
4036
+ expect ( childScope . theCtrl . constructor ) . toBe ( MyCtrl ) ;
4037
+ childScope . theCtrl . test ( ) ;
4038
+ } ) ;
4039
+ } ) ;
4040
+
4041
+
4042
+ it ( 'should re-install controllerAs and bindings for returned value from controller (isolate scope)' , function ( ) {
4043
+ var controllerCalled = false ;
4044
+ var myCtrl ;
4045
+
4046
+ function MyCtrl ( ) {
4047
+ }
4048
+ MyCtrl . prototype . test = function ( ) {
4049
+ expect ( this . data ) . toEqualData ( {
4050
+ 'foo' : 'bar' ,
4051
+ 'baz' : 'biz'
4052
+ } ) ;
4053
+ expect ( this . str ) . toBe ( 'Hello, world!' ) ;
4054
+ expect ( this . fn ( ) ) . toBe ( 'called!' ) ;
4055
+ }
4056
+
4057
+ module ( function ( $compileProvider , $controllerProvider ) {
4058
+ $controllerProvider . register ( 'myCtrl' , function ( ) {
4059
+ controllerCalled = true ;
4060
+ myCtrl = this ;
4061
+ return new MyCtrl ( ) ;
4062
+ } ) ;
4063
+ $compileProvider . directive ( 'fooDir' , valueFn ( {
4064
+ templateUrl : 'test.html' ,
4065
+ bindToController : true ,
4066
+ scope : {
4067
+ 'data' : '=dirData' ,
4068
+ 'str' : '@dirStr' ,
4069
+ 'fn' : '&dirFn'
4070
+ } ,
4071
+ controller : 'myCtrl as theCtrl'
4072
+ } ) ) ;
4073
+ } ) ;
4074
+ inject ( function ( $compile , $rootScope , $templateCache ) {
4075
+ $templateCache . put ( 'test.html' , '<p>isolate</p>' ) ;
4076
+ $rootScope . fn = valueFn ( 'called!' ) ;
4077
+ $rootScope . whom = 'world' ;
4078
+ $rootScope . remoteData = {
4079
+ 'foo' : 'bar' ,
4080
+ 'baz' : 'biz'
4081
+ } ;
4082
+ element = $compile ( '<div foo-dir dir-data="remoteData" ' +
4083
+ 'dir-str="Hello, {{whom}}!" ' +
4084
+ 'dir-fn="fn()"></div>' ) ( $rootScope ) ;
4085
+ $rootScope . $digest ( ) ;
4086
+ expect ( controllerCalled ) . toBe ( true ) ;
4087
+ var childScope = element . children ( ) . scope ( ) ;
4088
+ expect ( childScope ) . not . toBe ( $rootScope ) ;
4089
+ expect ( childScope . theCtrl ) . not . toBe ( myCtrl ) ;
4090
+ expect ( childScope . theCtrl . constructor ) . toBe ( MyCtrl ) ;
4091
+ childScope . theCtrl . test ( ) ;
4092
+ } ) ;
4093
+ } ) ;
3986
4094
} ) ;
3987
4095
3988
4096
0 commit comments