@@ -45,12 +45,19 @@ export function ng1ViewsBuilder(state: State) {
45
45
throw new Error ( `Cannot combine: ${ compKeys . join ( "|" ) } with: ${ nonCompKeys . join ( "|" ) } in stateview: 'name@${ state . name } '` ) ;
46
46
}
47
47
48
- // Dynamically build a template like "<component-name input1='$resolve.foo'></component-name>"
48
+ // Dynamically build a template like "<component-name input1=':: $resolve.foo'></component-name>"
49
49
config . templateProvider = [ '$injector' , function ( $injector ) {
50
50
const resolveFor = key => config . bindings && config . bindings [ key ] || key ;
51
51
const prefix = angular . version . minor >= 3 ? "::" : "" ;
52
- let attrs = getComponentInputs ( $injector , config . component )
53
- . map ( key => `${ kebobString ( key ) } ='${ prefix } $resolve.${ resolveFor ( key ) } '` ) . join ( " " ) ;
52
+ const attributeTpl = input => {
53
+ var attrName = kebobString ( input . name ) ;
54
+ var resolveName = resolveFor ( input . name ) ;
55
+ if ( input . type === '@' )
56
+ return `${ attrName } ='{{${ prefix } $resolve.${ resolveName } }}'` ;
57
+ return `${ attrName } ='${ prefix } $resolve.${ resolveName } '` ;
58
+ } ;
59
+
60
+ let attrs = getComponentInputs ( $injector , config . component ) . map ( attributeTpl ) . join ( " " ) ;
54
61
let kebobName = kebobString ( config . component ) ;
55
62
return `<${ kebobName } ${ attrs } ></${ kebobName } >` ;
56
63
} ] ;
@@ -70,27 +77,21 @@ export function ng1ViewsBuilder(state: State) {
70
77
return views ;
71
78
}
72
79
73
- // for ng 1.2 style, process the scope: { input: "=foo" } object
80
+ // for ng 1.2 style, process the scope: { input: "=foo" }
81
+ // for ng 1.3 through ng 1.5, process the component's bindToController: { input: "=foo" } object
74
82
const scopeBindings = bindingsObj => Object . keys ( bindingsObj || { } )
75
- . map ( key => [ key , / ^ [ = < ] ( .* ) / . exec ( bindingsObj [ key ] ) ] )
76
- . filter ( tuple => isDefined ( tuple [ 1 ] ) )
77
- . map ( tuple => tuple [ 1 ] [ 1 ] || tuple [ 0 ] ) ;
78
-
79
- // for ng 1.3+ bindToController or 1.5 component style, process a $$bindings object
80
- const bindToCtrlBindings = bindingsObj => Object . keys ( bindingsObj || { } )
81
- . filter ( key => ! ! / [ = < ] / . exec ( bindingsObj [ key ] . mode ) )
82
- . map ( key => bindingsObj [ key ] . attrName ) ;
83
+ . map ( key => [ key , / ^ ( [ = < @ ] ) [ ? ] ? ( .* ) / . exec ( bindingsObj [ key ] ) ] ) // [ 'input', [ '=foo', '=', 'foo' ] ]
84
+ . filter ( tuple => isDefined ( tuple ) && isDefined ( tuple [ 1 ] ) ) // skip malformed values
85
+ . map ( tuple => ( { name : tuple [ 1 ] [ 2 ] || tuple [ 0 ] , type : tuple [ 1 ] [ 1 ] } ) ) ; // { name: ('foo' || 'input'), type: '=' }
83
86
84
87
// Given a directive definition, find its object input attributes
85
88
// Use different properties, depending on the type of directive (component, bindToController, normal)
86
89
const getBindings = def => {
87
90
if ( isObject ( def . bindToController ) ) return scopeBindings ( def . bindToController ) ;
88
- if ( def . $$bindings && def . $$bindings . bindToController ) return bindToCtrlBindings ( def . $$bindings . bindToController ) ;
89
- if ( def . $$isolateBindings ) return bindToCtrlBindings ( def . $$isolateBindings ) ;
90
91
return < any > scopeBindings ( def . scope ) ;
91
92
} ;
92
93
93
- // Gets all the directive(s)' inputs ('=' and '<')
94
+ // Gets all the directive(s)' inputs ('@', '=', and '<')
94
95
function getComponentInputs ( $injector , name ) {
95
96
let cmpDefs = $injector . get ( name + "Directive" ) ; // could be multiple
96
97
if ( ! cmpDefs || ! cmpDefs . length ) throw new Error ( `Unable to find component named '${ name } '` ) ;
0 commit comments