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透视怎么安装,微乐自建房辅助工具在哪,教材教程(有挂教程)-哔哩哔哩1、完成wpk透...
普及透视!aapoker公共底... 普及透视!aapoker公共底牌,微乐南昌辅助神器,烘培教程(详细教程)-哔哩哔哩暗藏猫腻,小编详细...
详细透视!佛手在线有挂吗,微信... 详细透视!佛手在线有挂吗,微信小程序可以开挂吗,学习教程(有挂技术)-哔哩哔哩佛手在线有挂吗辅助器是...
辅助透视!hhpoker是内部... 辅助透视!hhpoker是内部控制吗,微乐贵阳捉鸡麻将挂软件,办法教程(有挂方式)-哔哩哔哩1、玩家...
解谜透视!wejoker内置辅... 解谜透视!wejoker内置辅助,微乐自建房怎么提高运气,法子教程(有挂透明挂)-哔哩哔哩1、wej...
解迷透视!wepoker作弊方... 解迷透视!wepoker作弊方法,微乐a3纸牌有脚本,大纲教程(真的有挂)-哔哩哔哩1)wepoke...
辅助透视!wpk透视是真的假的... 辅助透视!wpk透视是真的假的,微乐自建房脚本最新版本更新内容,步骤教程(有挂秘籍)-哔哩哔哩暗藏猫...
专业透视!智星菠萝有挂吗,微乐... 专业透视!智星菠萝有挂吗,微乐自建房脚本下载,模块教程(了解有挂)-哔哩哔哩1、下载好智星菠萝有挂吗...
有挂透视!aapoker透视怎... 有挂透视!aapoker透视怎么用,微乐自建房运势高有什么表现,机巧教程(有挂技术)-哔哩哔哩1、a...
解密透视!德普之星透视辅助,小... 解密透视!德普之星透视辅助,小程序微乐陕西挖坑辅助器,方式教程(有挂透明挂)-哔哩哔哩1、打开软件启...