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辅助器下载,wepoker私人局辅助,大纲教程(一贯真的是有挂)-哔哩哔哩1...
透视线上!hhpoker真的假... 透视线上!hhpoker真的假的(透视)开挂辅助神器(都是是有挂)-哔哩哔哩1、进入到hhpoker...
透视总结!德普之星透视免费(透... 透视总结!德普之星透视免费(透视)开挂辅助器(切实真的是有挂)-哔哩哔哩1、上手简单,内置详细流程视...
透视智能ai!智星菠萝有挂吗,... 透视智能ai!智星菠萝有挂吗,wepoker辅助器安装包定制,烘培教程(果然存在有挂)-哔哩哔哩1、...
透视靠谱!aapoker能控制... 透视靠谱!aapoker能控制牌吗(透视)开挂辅助脚本(总是是真的挂)-哔哩哔哩aapoker能控制...
辅助透视!hhpoker透视脚... 辅助透视!hhpoker透视脚本下载,pokemmo手机版透视脚本,窍门教程(其实是有挂)-哔哩哔哩...
透视plus!红龙poker辅... 透视plus!红龙poker辅助(透视)开挂辅助神器(真是真的有挂)-哔哩哔哩;1、许多玩家不知道红...
透视脚本!德扑圈有透视吗,hh... 透视脚本!德扑圈有透视吗,hhpoker免费透视脚本,秘籍教程(一贯是有挂)-哔哩哔哩1、很好的工具...
透视必胜!wpk辅助器是真的吗... 透视必胜!wpk辅助器是真的吗(透视)开挂辅助脚本(果然有挂)-哔哩哔哩1、操作简单,无需注册,只需...
透视有挂!wepoker怎么设... 透视有挂!wepoker怎么设置房间,wepoker能不能透视,妙招教程(竟然真的有挂)-哔哩哔哩w...