@@ -37,10 +37,20 @@ export function ng1ViewsBuilder(state: StateObject) {
37
37
ctrlKeys = [ 'controller' , 'controllerProvider' , 'controllerAs' , 'resolveAs' ] ,
38
38
compKeys = [ 'component' , 'bindings' , 'componentProvider' ] ,
39
39
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
+ }
41
51
42
52
let views : { [ key : string ] : Ng1ViewDeclaration } = { } ,
43
- viewsObject = state . views || { "$default" : pick ( state , allKeys ) } ;
53
+ viewsObject = state . views || { "$default" : pick ( state , allViewKeys ) } ;
44
54
45
55
forEach ( viewsObject , function ( config : Ng1ViewDeclaration , name : string ) {
46
56
// Account for views: { "": { template... } }
@@ -51,6 +61,7 @@ export function ng1ViewsBuilder(state: StateObject) {
51
61
// Make a shallow copy of the config object
52
62
config = extend ( { } , config ) ;
53
63
64
+ // Do not allow a view to mix props for component-style view with props for template/controller-style view
54
65
if ( hasAnyKey ( compKeys , config ) && hasAnyKey ( nonCompKeys , config ) ) {
55
66
throw new Error ( `Cannot combine: ${ compKeys . join ( "|" ) } with: ${ nonCompKeys . join ( "|" ) } in stateview: '${ name } @${ state . name } '` ) ;
56
67
}
0 commit comments