Skip to content

Commit

Permalink
fix(ng2.uiSref): Fix anchor href generation
Browse files Browse the repository at this point in the history
fix(ng2.uiSref): Fix relative srefs
  • Loading branch information
christopherthielen committed Apr 3, 2016
1 parent fcb15c5 commit 98b5b42
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/ng2/directives.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {UiSref} from "../ng2/uiSref";
import {UiSref, AnchorUiSref} from "../ng2/uiSref";
import {UiSrefActive} from "../ng2/uiSrefActive";
import {UiView} from "../ng2/uiView";
import {UiSrefStatus} from "./uiSrefStatus";
Expand All @@ -8,4 +8,4 @@ export * from "./uiSref";
export * from "./uiSrefStatus";
export * from "./uiSrefActive";

export let UIROUTER_DIRECTIVES = [UiSref, UiView, UiSrefActive, UiSrefStatus];
export let UIROUTER_DIRECTIVES = [UiSref, AnchorUiSref, UiView, UiSrefActive, UiSrefStatus];
2 changes: 1 addition & 1 deletion src/ng2/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const UIROUTER_PROVIDERS: Provider[] = [

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

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

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

Expand Down
20 changes: 14 additions & 6 deletions src/ng2/uiSref.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
/** @module ng2 */ /** */
import {UIRouter} from "../router";
import {Directive} from "angular2/core";
import {Directive, Inject} from "angular2/core";
import {Optional} from "angular2/core";
import {Input} from "angular2/core";
import {ElementRef} from "angular2/core";
import {Renderer} from "angular2/core";
import {UiView} from "./uiView";
import {ViewContext} from "../view/interface";
import {extend} from "../common/common";

@Directive({ selector: 'a[uiSref]' })
export class AnchorUiSref {
constructor( public _el: ElementRef, public _renderer: Renderer) { }
constructor(public _el: ElementRef, public _renderer: Renderer) { }
update(href) {
this._renderer.setElementProperty(this._el, 'href', href);
this._renderer.setElementProperty(this._el.nativeElement, 'href', href);
}
}

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

constructor(
private _router: UIRouter,
@Inject(UiView.INJECT.context) public context: ViewContext,
@Optional() private _anchorUiSref: AnchorUiSref
) { }

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

update() {
if (this._anchorUiSref) {
this._anchorUiSref.update(this._router.stateService.href(this.state, this.params));
this._anchorUiSref.update(this._router.stateService.href(this.state, this.params, this.getOptions()));
}
}

getOptions() {
let defOpts = { relative: this.context.name, inherit: true };
return extend(defOpts, this.options || {});
}

go() {
this._router.stateService.go(this.state, this.params, this.options);
this._router.stateService.go(this.state, this.params, this.getOptions());
return false;
}
}
Expand Down
1 change: 0 additions & 1 deletion src/ng2/uiView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ export class UiView {
ngOnInit() {
let parentFqn = this.parentFqn;
let name = this.name || '$default';
console.log(`parentFqn: ${parentFqn}`);

this.uiViewData = {
id: id++,
Expand Down

0 comments on commit 98b5b42

Please sign in to comment.