1
1
/** @module ng2 */ /** */
2
2
import { UIRouter } from "../router" ;
3
- import { Directive } from "angular2/core" ;
3
+ import { Directive , Inject } from "angular2/core" ;
4
4
import { Optional } from "angular2/core" ;
5
- import { Input } from "angular2/core" ;
6
5
import { ElementRef } from "angular2/core" ;
7
6
import { Renderer } from "angular2/core" ;
7
+ import { UiView } from "./uiView" ;
8
+ import { ViewContext } from "../view/interface" ;
9
+ import { extend } from "../common/common" ;
8
10
9
11
@Directive ( { selector : 'a[uiSref]' } )
10
12
export class AnchorUiSref {
11
- constructor ( public _el : ElementRef , public _renderer : Renderer ) { }
13
+ constructor ( public _el : ElementRef , public _renderer : Renderer ) { }
12
14
update ( href ) {
13
- this . _renderer . setElementProperty ( this . _el , 'href' , href ) ;
15
+ this . _renderer . setElementProperty ( this . _el . nativeElement , 'href' , href ) ;
14
16
}
15
17
}
16
18
@@ -26,6 +28,7 @@ export class UiSref {
26
28
27
29
constructor (
28
30
private _router : UIRouter ,
31
+ @Inject ( UiView . INJECT . context ) public context : ViewContext ,
29
32
@Optional ( ) private _anchorUiSref : AnchorUiSref
30
33
) { }
31
34
@@ -39,12 +42,17 @@ export class UiSref {
39
42
40
43
update ( ) {
41
44
if ( this . _anchorUiSref ) {
42
- this . _anchorUiSref . update ( this . _router . stateService . href ( this . state , this . params ) ) ;
45
+ this . _anchorUiSref . update ( this . _router . stateService . href ( this . state , this . params , this . getOptions ( ) ) ) ;
43
46
}
44
47
}
45
48
49
+ getOptions ( ) {
50
+ let defOpts = { relative : this . context . name , inherit : true } ;
51
+ return extend ( defOpts , this . options || { } ) ;
52
+ }
53
+
46
54
go ( ) {
47
- this . _router . stateService . go ( this . state , this . params , this . options ) ;
55
+ this . _router . stateService . go ( this . state , this . params , this . getOptions ( ) ) ;
48
56
return false ;
49
57
}
50
58
}
0 commit comments