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

  

相关内容

热门资讯

透视线上!wpk透视辅助靠谱吗... 透视线上!wpk透视辅助靠谱吗,wepoker透视app下载,安装教程(固有有挂)1、点击下载安装,...
透视玄学!智星菠萝辅助,wep... 透视玄学!智星菠萝辅助,wepoker有机器人吗,2025新版教程(竟然是有挂);小薇(透视辅助)致...
透视插件!德普之星透视辅助io... 透视插件!德普之星透视辅助ios,we-poker辅助器,详细教程(果然是真的有挂)1、许多玩家不知...
透视黑科技!德普之星透视辅助,... 《透视黑科技!德普之星透视辅助,佛手大菠萝有挂吗,玩家教程(原生存在有挂)》 德普之星透视辅助软件透...
透视透视!wpk辅助购买,aa... 透视透视!wpk辅助购买,aa poker透视软件,新2025教程(原先有挂);原来确实真的有挂(需...
透视科技!aapoker辅助是... 透视科技!aapoker辅助是真的吗,哈糖大菠萝攻略,详细教程(原先存在有挂);科技详细教程Q群《1...
透视app!hhpoker万能... 透视app!hhpoker万能辅助器,wepoker私人局辅助挂,科技教程(原生有挂)是一款可以让一...
透视安卓版!wpk透视工作室,... 透视安卓版!wpk透视工作室,wepoker透视脚本免费下载,必备教程(切实是有挂);科技安装教程;...
透视新版!wepoker透视脚... 透视新版!wepoker透视脚本免费下载,wepoker辅助透视软件,技巧教程(固有是真的有挂);致...
透视透视!德普之星辅助功能如何... 您好,德普之星辅助功能如何打开这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302】很...