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

  

相关内容

热门资讯

分享个大家!德扑圈有透视吗,微... 分享个大家!德扑圈有透视吗,微扑克透视脚本,本来有挂(有挂总结)1)免费钻石:进一步探索免费脚本大陆...
我来教大家!wpk辅助,wep... 我来教大家!wpk辅助,wepoker透视有没有,好像是真的有挂(真是有挂)1、上手简单,内置详细流...
实测揭晓!hhpoker德州挂... 实测揭晓!hhpoker德州挂真的有吗,福建大菠萝万能辅助器,好像是有挂(讲解有挂)1、下载好正确养...
科普攻略!wpk插件辅助,we... 科普攻略!wpk插件辅助,wepoker透视功能下载,确实有挂(揭秘有挂)透视方法中分为三种模型:靠...
揭秘关于!pokemmo手机版... 揭秘关于!pokemmo手机版脚本免费,wpk私人局辅助是真的吗,好像存在有挂(确实有挂)1)有没有...
玩家必看!wepoker破解器... 玩家必看!wepoker破解器,pokemmo辅助官网,确实有挂(真是有挂)1、操作简单,无需手机版...
分享一款!wejoker辅助软... 分享一款!wejoker辅助软件,wpk作弊,一直有挂(有挂功能)1、在插件功能辅助器技巧中,中转单...
重大通报!智星菠萝辅助,pok... 重大通报!智星菠萝辅助,pokerworld修改器,切实存在有挂(有挂教学)1、许多玩家不知道辅助怎...
最新技巧!拱趴大菠萝机器人,德... 最新技巧!拱趴大菠萝机器人,德州辅助工具到底怎么样,原来真的有挂(确实有挂)1、完成有辅助插件,帮助...
2024教程!hhpoker到... 2024教程!hhpoker到底可以作弊码,德普之星透视,竟然有挂(有挂方式)1、起透看视 辅助软件...