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,如下所示:

  

相关内容

热门资讯

外挂手册!拱趴大菠萝万能挂,a... 外挂手册!拱趴大菠萝万能挂,agpoker辅助-竟然一直都是有辅助教程(哔哩哔哩)1、拱趴大菠萝万能...
外挂手筋!werplan怎么透... 外挂手筋!werplan怎么透视,哈糖大菠萝有挂吗-果然有辅助技巧(哔哩哔哩)1、下载好哈糖大菠萝有...
外挂窍要!德普之星透视辅助软件... 外挂窍要!德普之星透视辅助软件激活码,约局吧德州真的存在透视吗-真是一直总是有辅助教程(哔哩哔哩)1...
外挂模块!newpoker脚本... 外挂模块!newpoker脚本,xpoker辅助器-原来一直总是有辅助教程(哔哩哔哩)xpoker辅...
外挂指引!德普之星透视辅助软件... 外挂指引!德普之星透视辅助软件下载,智星菠萝有挂吗-本来一直总是有辅助工具(哔哩哔哩)1、用户打开应...
外挂攻略!拱趴大菠萝机器人,德... 外挂攻略!拱趴大菠萝机器人,德州圈脚本-切实真的是有辅助脚本(哔哩哔哩)拱趴大菠萝机器人破解侠是真的...
外挂手段!哈糖大菠萝怎么挂,德... 外挂手段!哈糖大菠萝怎么挂,德州局透视-总是真的是有辅助脚本(哔哩哔哩)1、起透看视 哈糖大菠萝怎么...
外挂指南书!impoker辅助... 外挂指南书!impoker辅助,sohoo开挂辅助-原来真的有辅助教程(哔哩哔哩)1、sohoo开挂...
外挂办法!约局吧作必弊脚本,a... 外挂办法!约局吧作必弊脚本,agpoker辅助-一直真的有辅助神器(哔哩哔哩)1、约局吧作必弊脚本辅...
外挂指南!线上德州的辅助器是什... 外挂指南!线上德州的辅助器是什么,佛手大菠萝13道挂哪里-确实是真的有辅助工具(哔哩哔哩)1、上手简...