Angular调用SpringBoot的index.html该如何实现?
创始人
2024-10-24 12:01:33
0
  1. 在Spring Boot的Controller中创建返回index.html的Endpoint,如下所示:
@Controller
public class HomeController {

    @RequestMapping("/")
    public String home() {
        return "index.html";
    }
}
  1. 在Angular中创建一个Service,使用HttpClient来获取Spring Boot的Endpoint返回的index.html文件,例如:
@Injectable()
export class HomeService {

  constructor(private http: HttpClient) { }

  public getHome(): Observable {
    return this.http.get('/api/home', {responseType: 'text'});
  }
}
  1. 在Angular的Component中调用HomeService来获取index.html文件,例如:
@Component({
  selector: 'app-home',
  template: '
' }) export class HomeComponent implements OnInit { public homeHtml: string; constructor(private homeService: HomeService) { } ngOnInit() { this.homeService.getHome().subscribe( (response: string) => { this.homeHtml = response; }, (error: HttpErrorResponse) => { console.error(error); } ); } }
  1. 将Angular的index.html修改为调用Component,如下所示:

  

相关内容

热门资讯

了解透视!德州局透视脚本免费版... 了解透视!德州局透视脚本免费版下载手机版,约局吧如何查看是否有挂(透视)总是一直总是有辅助软件(哔哩...
据权威媒体报道!wepoker... 据权威媒体报道!wepoker开脚本视频,玉兔追月有挂吗,确实真的有辅助神器(哔哩哔哩)1、下载好玉...
关于透视!newpoker怎么... 关于透视!newpoker怎么安装脚本,哈糖大菠萝挂法(透视)都是真的是有辅助工具(哔哩哔哩)1、n...
据监测!aapoker真的假的... 据监测!aapoker真的假的,山西扣点点辅助工具,竟然是真的有辅助神器(哔哩哔哩)1、山西扣点点辅...
揭幕透视!聚星ai辅助工具下载... 揭幕透视!聚星ai辅助工具下载,红龙poker辅助(透视)原来有辅助工具(哔哩哔哩)聚星ai辅助工具...
今天上午!wpk有作必弊吗,玉... 今天上午!wpk有作必弊吗,玉海楼辅助器,一贯真的有辅助教程(哔哩哔哩)运玉海楼辅助器辅助工具,进入...
揭幕透视!约局吧德州可以透视吗... 揭幕透视!约局吧德州可以透视吗,德州局脚本(透视)本来是有辅助软件(哔哩哔哩)1、该软件可以轻松地帮...
长期以来!epoker透视底牌... 长期以来!epoker透视底牌,丽水都莱大菠萝脚本辅助,确实是真的有辅助神器(哔哩哔哩)亲,关键说明...
解迷透视!约局吧德州透视,po... 解迷透视!约局吧德州透视,pokermaster修改器(透视)好像有辅助方法(哔哩哔哩)1、进入到约...
今天下午!pokerworld... 今天下午!pokerworld破解版下载,填大坑小程序辅助器,原来真的有辅助软件(哔哩哔哩)1、金币...