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

  

相关内容

热门资讯

一分钟教会你!hhpoker有... 1、一分钟教会你!hhpoker有辅助吗,wepoker脚本下载,曝光教程(有挂透明);详细教程。2...
推荐攻略!wejoker辅助软... 1、推荐攻略!wejoker辅助软件价格,wepoker底牌透视脚本,大神讲解(有挂方法)(UU p...
重磅来袭!德州真人透视脚本,p... 1、重磅来袭!德州真人透视脚本,pokerworld修改器,技巧教程(有挂透视);详细教程。2、德州...
科技分享!HH平台挂,aapo... 科技分享!HH平台挂,aapoker安装包怎么使用,黑科技教程(有挂辅助);原来确实真的有挂(需添加...
玩家必看秘籍!佛手在线大菠萝技... 玩家必看秘籍!佛手在线大菠萝技巧,we-poker靠谱吗,力荐教程(有挂透视);致您一封信;亲爱佛手...
终于知道!pokemmo脚本辅... 终于知道!pokemmo脚本辅助,拱趴大菠萝挂哪里,高科技教程(有挂方法);科技安装教程;13670...
玩家爆料!wpk插件辅助,hh... 自定义hhpoker怎么开透视系统规律,只需要输入自己想要的开挂功能,一键便可以生成出微扑克专用辅助...
玩家必备科技!拱趴大菠萝开挂方... 玩家必备科技!拱趴大菠萝开挂方法,wepoker辅助器安装包定制,力荐教程(有挂技巧);建议优先通过...
2024教程!约局吧德州可以透... 2024教程!约局吧德州可以透视吗,德州hhpoker脚本,技巧教程(有挂技巧);玩家必备必赢加哟《...
今日重大通报!wepoker有... 今日重大通报!wepoker有没有机器人,wepoker有机器人吗,2025教程(有挂透明)是由北京...