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

  

相关内容

热门资讯

透视模板!xpoker辅助怎么... 透视模板!xpoker辅助怎么用,aapoker能控制牌吗(透视)切实真的是有挂(哔哩哔哩)1、游戏...
透视窍要!impoker辅助,... 透视窍要!impoker辅助,红龙poker辅助器免费观看(透视)本来真的是有脚本脚本(哔哩哔哩)红...
透视窍要!wepoker私人局... 透视窍要!wepoker私人局怎么玩,wepoker轻量版透视系统(透视)切实存在有挂(哔哩哔哩)1...
透视窍门!wpk透视辅助靠谱吗... 透视窍门!wpk透视辅助靠谱吗,wpk俱乐部怎么作必弊(透视)本来是真的透视挂(哔哩哔哩)1、实时w...
透视操作!aapoker插件,... 透视操作!aapoker插件,wepoker私局辅助(透视)切实是真的挂(哔哩哔哩)1、起透看视 w...
透视妙招!wpk是真的还是假的... 透视妙招!wpk是真的还是假的,wpk透视是真的吗(透视)都是真的是有透视软件(哔哩哔哩)1、金币登...
透视总结!pokermaste... 透视总结!pokermaster修改器,wepoker科技辅助器(透视)真是真的是有挂(哔哩哔哩)1...
透视模块!wpk辅助器是真的吗... 透视模块!wpk辅助器是真的吗,wpk免费辅助(透视)原来有脚本插件(哔哩哔哩)1、起透看视 wpk...
透视手册!wepoker免费脚... 透视手册!wepoker免费脚本咨询,红龙poker辅助(透视)一直有挂(哔哩哔哩)进入游戏-大厅左...
透视演示!有哪些免费的wpk作... 透视演示!有哪些免费的wpk作必弊码,wpk辅助是什么(透视)竟然真的有挂(哔哩哔哩)1、有哪些免费...