调用外部HTML Angular 7+ Net Core可以通过以下步骤实现:
<iframe>
标签来加载外部HTML文件。例如:<iframe [src]="'path/to/external/file.html'"></iframe>
import { HttpClient } from '@angular/common/http';
@Component({
// 组件配置
})
export class ExternalHtmlComponent implements OnInit {
externalHtml: string;
constructor(private http: HttpClient) { }
ngOnInit() {
this.http.get('path/to/external/file.html', { responseType: 'text' })
.subscribe((html: string) => {
this.externalHtml = html;
});
}
}
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "path/to/external")),
RequestPath = "/external"
});
[Route("external/file.html")]
public IActionResult ExternalHtml()
{
return File("~/path/to/external/file.html", "text/html");
}
import { HttpClient } from '@angular/common/http';
@Component({
// 组件配置
})
export class ExternalHtmlComponent implements OnInit {
externalHtml: string;
constructor(private http: HttpClient) { }
ngOnInit() {
this.http.get('https://your-net-core-api/external/file.html', { responseType: 'text' })
.subscribe((html: string) => {
this.externalHtml = html;
});
}
}
这样,就可以通过调用外部HTML Angular 7+ Net Core来加载和显示外部HTML内容了。请注意,上述代码中的路径和URL需要根据实际情况进行修改。
领取专属 10元无门槛券
手把手带您无忧上云