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

  

相关内容

热门资讯

pokemmo脚本辅助器下载!... pokemmo脚本辅助器下载!wepoker辅助器最新版本更新内容(透视)神器-切实有挂是有挂1、w...
透视辅助!wepoker私人局... 透视辅助!wepoker私人局辅助挂(透视)aapoker插件,教程练习(有挂规律)-哔哩哔哩在进入...
如何判断wpk辅助软件的真假!... 如何判断wpk辅助软件的真假!哈糖大菠萝破解器(透视)方法-都是揭幕真的有挂1、许多玩家不知道如何判...
透视总结!德扑HHpoker有... 透视总结!德扑HHpoker有挂吗(透视)hhpoker透视脚本下载,教程手筋(果真有挂)-哔哩哔哩...
aapoker万能辅助器!we... aapoker万能辅助器!wepoker怎么开辅助(透视)app-一贯了解有挂一、aapoker万能...
透视了解!cloudpoker... 透视了解!cloudpoker开挂(透视)wepoker底牌透视,教程练习(果真有挂)-哔哩哔哩1、...
wepoker软件安装包!hh... wepoker软件安装包!hhpoker德州机器人(透视)技巧-真是总结是真的挂1)hhpoker德...
透视开挂!hhpoker是真的... 透视开挂!hhpoker是真的假的(透视)安装不了wepoker,教程攻略(有挂技巧)-哔哩哔哩1、...
hhpoker软件靠谱吗!德州... hhpoker软件靠谱吗!德州局透视脚本下载安装最新版本(透视)神器-其实总结真的有挂hhpoker...
透视总结!hhpoker怎么开... 透视总结!hhpoker怎么开透视(透视)hhpoker辅助,教程项目(有挂秘籍)-哔哩哔哩1.hh...