File tree Expand file tree Collapse file tree 2 files changed +43
-1
lines changed Expand file tree Collapse file tree 2 files changed +43
-1
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,11 @@ import { Subscription } from "rxjs/Subscription";
14
14
export class AnchorUISref {
15
15
constructor ( public _el : ElementRef , public _renderer : Renderer ) { }
16
16
update ( href : string ) {
17
- this . _renderer . setElementProperty ( this . _el . nativeElement , 'href' , href ) ;
17
+ if ( href && href != '' ) {
18
+ this . _renderer . setElementProperty ( this . _el . nativeElement , 'href' , href ) ;
19
+ } else {
20
+ this . _el . nativeElement . removeAttribute ( 'href' ) ;
21
+ }
18
22
}
19
23
}
20
24
Original file line number Diff line number Diff line change
1
+ import { Component , NO_ERRORS_SCHEMA } from "@angular/core" ;
2
+ import { async , ComponentFixture , TestBed } from '@angular/core/testing' ;
3
+ import { By } from '@angular/platform-browser' ;
4
+ import { DebugElement } from '@angular/core' ;
5
+
6
+ import { UIRouterModule } from '../src/uiRouterNgModule' ;
7
+ import { UISref } from '../src/directives/uiSref' ;
8
+
9
+ describe ( 'uiSref' , ( ) => {
10
+ describe ( 'empty links' , ( ) => {
11
+ @Component ( {
12
+ template : `
13
+ <a [uiSref]="null"></a>
14
+ <a [uiSref]="''"></a>
15
+ `
16
+ } )
17
+ class TestComponent { }
18
+
19
+ let des : DebugElement [ ] ;
20
+ let comp : TestComponent ;
21
+ let fixture : ComponentFixture < TestComponent > ;
22
+
23
+ beforeEach ( ( ) => {
24
+ fixture = TestBed . configureTestingModule ( {
25
+ declarations : [ TestComponent ] ,
26
+ imports : [ UIRouterModule ]
27
+ } ) . createComponent ( TestComponent ) ;
28
+ fixture . detectChanges ( ) ;
29
+ des = fixture . debugElement . queryAll ( By . directive ( UISref ) ) ;
30
+ } ) ;
31
+
32
+ it ( 'should not bind "null" string to `href`' , ( ) => {
33
+ expect ( des [ 0 ] . nativeElement . hasAttribute ( 'href' ) ) . toBeFalsy ( ) ;
34
+ expect ( des [ 1 ] . nativeElement . hasAttribute ( 'href' ) ) . toBeFalsy ( ) ;
35
+ } ) ;
36
+ } ) ;
37
+ } ) ;
38
+
You can’t perform that action at this time.
0 commit comments