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

  

相关内容

热门资讯

目前来看!wepoker手机插... 目前来看!wepoker手机插件,中至赣牌圈挂件多少钱一个,真是真的有挂(曝光2025教程)-哔哩哔...
透视辅助!werplan免费挂... 透视辅助!werplan免费挂下载,pokemmo免费脚本,学习教程(一直真的有挂)-哔哩哔哩暗藏猫...
透视检测!wpk软件是正规的吗... 透视检测!wpk软件是正规的吗(透视)开挂辅助器(真是真的有挂)-哔哩哔哩1、wpk软件是正规的吗a...
透视私人局!hhpoker德州... 透视私人局!hhpoker德州真的假的,逸游辅助怎么下载安装,切实是真的挂(分享详细教程)-哔哩哔哩...
透视规律!哈糖大菠萝开挂(透视... 透视规律!哈糖大菠萝开挂(透视)开挂辅助脚本(确实是有挂)-哔哩哔哩哈糖大菠萝开挂是一种具有地方特色...
透视有挂!德普之星透视免费,w... 透视有挂!德普之星透视免费,wepoker有插件吗,办法教程(本来真的是有挂)-哔哩哔哩1.德普之星...
透视真的!德州来玩辅助器,起点... 透视真的!德州来玩辅助器,起点休闲辅助,确实真的是有挂(总结详细教程)-哔哩哔哩1、玩家可以在起点休...
透视必胜!hhpoker透视脚... 透视必胜!hhpoker透视脚本(透视)开挂辅助攻略(真是存在有挂)-哔哩哔哩一、hhpoker透视...
透视有挂!wepoker有辅助... 透视有挂!wepoker有辅助工具吗,哈糖大菠萝免费辅助器,总结教程(好像存在有挂)-哔哩哔哩该软件...
最新消息!拱趴大菠萝十三水辅助... 最新消息!拱趴大菠萝十三水辅助,永久免费脚本透视工具,好像真的有挂(解密分享教程)-哔哩哔哩1、完成...