@@ -37,10 +37,20 @@ export function ng1ViewsBuilder(state: StateObject) {
3737 ctrlKeys = [ 'controller' , 'controllerProvider' , 'controllerAs' , 'resolveAs' ] ,
3838 compKeys = [ 'component' , 'bindings' , 'componentProvider' ] ,
3939 nonCompKeys = tplKeys . concat ( ctrlKeys ) ,
40- allKeys = compKeys . concat ( nonCompKeys ) ;
40+ allViewKeys = compKeys . concat ( nonCompKeys ) ;
41+
42+ // Do not allow a state to have both state-level props and also a `views: {}` property.
43+ // A state without a `views: {}` property can declare properties for the `$default` view as properties of the state.
44+ // However, the `$default` approach should not be mixed with a separate `views: ` block.
45+ if ( isDefined ( state . views ) && hasAnyKey ( allViewKeys , state ) ) {
46+ throw new Error ( `State '${ state . name } ' has a 'views' object. ` +
47+ `It cannot also have "view properties" at the state level. ` +
48+ `Move the following properties into a view (in the 'views' object): ` +
49+ ` ${ allViewKeys . filter ( key => isDefined ( state [ key ] ) ) . join ( ", " ) } ` ) ;
50+ }
4151
4252 let views : { [ key : string ] : Ng1ViewDeclaration } = { } ,
43- viewsObject = state . views || { "$default" : pick ( state , allKeys ) } ;
53+ viewsObject = state . views || { "$default" : pick ( state , allViewKeys ) } ;
4454
4555 forEach ( viewsObject , function ( config : Ng1ViewDeclaration , name : string ) {
4656 // Account for views: { "": { template... } }
@@ -51,6 +61,7 @@ export function ng1ViewsBuilder(state: StateObject) {
5161 // Make a shallow copy of the config object
5262 config = extend ( { } , config ) ;
5363
64+ // Do not allow a view to mix props for component-style view with props for template/controller-style view
5465 if ( hasAnyKey ( compKeys , config ) && hasAnyKey ( nonCompKeys , config ) ) {
5566 throw new Error ( `Cannot combine: ${ compKeys . join ( "|" ) } with: ${ nonCompKeys . join ( "|" ) } in stateview: '${ name } @${ state . name } '` ) ;
5667 }
0 commit comments