@@ -45,12 +45,19 @@ export function ng1ViewsBuilder(state: State) {
4545 throw new Error ( `Cannot combine: ${ compKeys . join ( "|" ) } with: ${ nonCompKeys . join ( "|" ) } in stateview: 'name@${ state . name } '` ) ;
4646 }
4747
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>"
4949 config . templateProvider = [ '$injector' , function ( $injector ) {
5050 const resolveFor = key => config . bindings && config . bindings [ key ] || key ;
5151 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 ( " " ) ;
5461 let kebobName = kebobString ( config . component ) ;
5562 return `<${ kebobName } ${ attrs } ></${ kebobName } >` ;
5663 } ] ;
@@ -70,27 +77,21 @@ export function ng1ViewsBuilder(state: State) {
7077 return views ;
7178}
7279
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
7482const 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: '=' }
8386
8487// Given a directive definition, find its object input attributes
8588// Use different properties, depending on the type of directive (component, bindToController, normal)
8689const getBindings = def => {
8790 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 ) ;
9091 return < any > scopeBindings ( def . scope ) ;
9192} ;
9293
93- // Gets all the directive(s)' inputs ('=' and '<')
94+ // Gets all the directive(s)' inputs ('@', '=', and '<')
9495function getComponentInputs ( $injector , name ) {
9596 let cmpDefs = $injector . get ( name + "Directive" ) ; // could be multiple
9697 if ( ! cmpDefs || ! cmpDefs . length ) throw new Error ( `Unable to find component named '${ name } '` ) ;
0 commit comments