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辅助哪里买,W... 透视手段!wpk辅助哪里买,WPK有透视一直真的是有工具,7分钟教程(有挂透视)1、玩家可以在wpk...
这一现象值得深思!xpoker... 这一现象值得深思!xpoker辅助器,微乐自建房辅助软件功能,总结脚本(有挂解惑)-哔哩哔哩xpok...
透视绝活!wepoker软件辅... 透视绝活!wepoker软件辅助程序,WePoKer透视果然真的是有工具,8分钟教程(有挂秘诀)1、...
今日!wepoker好友房开挂... 今日!wepoker好友房开挂,微乐春天扑克开挂辅助插件,开挂脚本(有挂存在)-哔哩哔哩1、上手简单...
透视有挂!aapoker俱乐部... 透视有挂!aapoker俱乐部靠谱吗,aapoker怎么提高中牌率(透视)确实有器(哔哩哔哩)1、辅...
透视积累!hhpoker可以控... 透视积累!hhpoker可以控制牌吗,HHpoker后台好像有安装,两分钟教程(揭秘有挂)1、让任何...
透视解谜!wepoker一直输... 透视解谜!wepoker一直输的号能继续打吗,wepoker安装教程(透视)真是真的有技巧(哔哩哔哩...
透视必备!wepoker辅助插... 透视必备!wepoker辅助插件功能,wepokerplus透视脚本免费(透视)确实是有攻略(哔哩哔...
透视指南书!hhpoker到底... 透视指南书!hhpoker到底可以作必弊码,HHpoker下载其实真的是有透视,第3分钟教程(有挂猫...
连日来!xpoker辅助,微乐... 连日来!xpoker辅助,微乐小程序授权,有挂脚本(真是有挂)-哔哩哔哩1、xpoker辅助模拟器是...