Skip to content

Commit 98b5b42

Browse files
fix(ng2.uiSref): Fix anchor href generation
fix(ng2.uiSref): Fix relative srefs
1 parent fcb15c5 commit 98b5b42

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

src/ng2/directives.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {UiSref} from "../ng2/uiSref";
1+
import {UiSref, AnchorUiSref} from "../ng2/uiSref";
22
import {UiSrefActive} from "../ng2/uiSrefActive";
33
import {UiView} from "../ng2/uiView";
44
import {UiSrefStatus} from "./uiSrefStatus";
@@ -8,4 +8,4 @@ export * from "./uiSref";
88
export * from "./uiSrefStatus";
99
export * from "./uiSrefActive";
1010

11-
export let UIROUTER_DIRECTIVES = [UiSref, UiView, UiSrefActive, UiSrefStatus];
11+
export let UIROUTER_DIRECTIVES = [UiSref, AnchorUiSref, UiView, UiSrefActive, UiSrefStatus];

src/ng2/providers.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export const UIROUTER_PROVIDERS: Provider[] = [
4949

5050
provide(UIRouterGlobals, { useFactory: (r: UIRouter) => { return r.globals; }, deps: [UIRouter]}),
5151

52-
provide(UiView.INJECT.context, { useFactory: (r: StateRegistry) => { console.log(r); return r.root(); }, deps: [StateRegistry]} ),
52+
provide(UiView.INJECT.context, { useFactory: (r: StateRegistry) => { return r.root(); }, deps: [StateRegistry]} ),
5353

5454
provide(UiView.INJECT.fqn, { useValue: null })
5555

src/ng2/uiSref.ts

+14-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
/** @module ng2 */ /** */
22
import {UIRouter} from "../router";
3-
import {Directive} from "angular2/core";
3+
import {Directive, Inject} from "angular2/core";
44
import {Optional} from "angular2/core";
5-
import {Input} from "angular2/core";
65
import {ElementRef} from "angular2/core";
76
import {Renderer} from "angular2/core";
7+
import {UiView} from "./uiView";
8+
import {ViewContext} from "../view/interface";
9+
import {extend} from "../common/common";
810

911
@Directive({ selector: 'a[uiSref]' })
1012
export class AnchorUiSref {
11-
constructor( public _el: ElementRef, public _renderer: Renderer) { }
13+
constructor(public _el: ElementRef, public _renderer: Renderer) { }
1214
update(href) {
13-
this._renderer.setElementProperty(this._el, 'href', href);
15+
this._renderer.setElementProperty(this._el.nativeElement, 'href', href);
1416
}
1517
}
1618

@@ -26,6 +28,7 @@ export class UiSref {
2628

2729
constructor(
2830
private _router: UIRouter,
31+
@Inject(UiView.INJECT.context) public context: ViewContext,
2932
@Optional() private _anchorUiSref: AnchorUiSref
3033
) { }
3134

@@ -39,12 +42,17 @@ export class UiSref {
3942

4043
update() {
4144
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()));
4346
}
4447
}
4548

49+
getOptions() {
50+
let defOpts = { relative: this.context.name, inherit: true };
51+
return extend(defOpts, this.options || {});
52+
}
53+
4654
go() {
47-
this._router.stateService.go(this.state, this.params, this.options);
55+
this._router.stateService.go(this.state, this.params, this.getOptions());
4856
return false;
4957
}
5058
}

src/ng2/uiView.ts

-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ export class UiView {
6767
ngOnInit() {
6868
let parentFqn = this.parentFqn;
6969
let name = this.name || '$default';
70-
console.log(`parentFqn: ${parentFqn}`);
7170

7271
this.uiViewData = {
7372
id: id++,

0 commit comments

Comments
 (0)