如何使用<a> tag in angular

时间:2018-05-23 11:32:17

标签: asp.net angular redirect asp.net-web-api tags

My Existing code

<a class="getStart-button line blue" href="#" (click)="navigateBack()" title="Back">Back</a>

I want to use code without href like this:

 <a class="getStart-button line blue" (click)="navigateBack()" title="Back">Back</a>

1 个答案:

答案 0 :(得分:1)

好的,试试这个。

<a class="getStart-button line blue" (click)="navigateBack()" title="Back">Back</a>

在component.ts

   import { Location, LocationStrategy, PathLocationStrategy } from '@angular/common';

@Component({
  selector: 'selector',
  providers: [Location, { provide: LocationStrategy, useClass: PathLocationStrategy }],
  template: `your tempalte`
})

export class Component {
  constructor(private location: Location) { }

  public navigateBack(): void {
    this.location.back();
  }
}

here中阅读更多角度定位服务

希望这有帮助。