test2.component.html
<p>test2 works!</p>
<a href="{{url}}">百度</a>
<a [href]="url">百度2</a>
test1.component.spec.ts
import { ComponentFixture, TestBed } from '@angular/core/testing';import { Test2Component } from './test2.component';describe('Test2Component', () => {let component: Test2Component;let fixture: ComponentFixture<Test2Component>;beforeEach(async () => {await TestBed.configureTestingModule({declarations: [ Test2Component ]}).compileComponents();});beforeEach(() => {fixture = TestBed.createComponent(Test2Component);component = fixture.componentInstance;fixture.detectChanges();});it('should create', () => {expect(component).toBeTruthy();});
});
test1.component.ts
import { Component, OnInit } from '@angular/core';@Component({selector: 'app-test2',templateUrl: './test2.component.html',styleUrls: ['./test2.component.css']
})
export class Test2Component implements OnInit {constructor() { }ngOnInit(): void {this.url="http://www.baidu.com"}}
运行结果