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、进入游戏-大厅左侧-新手福利-激活码辅...
透视美元局!aapoker破解... 透视美元局!aapoker破解侠是真的吗(透视)插件(一贯真的有挂);一、aapoker破解侠是真的...
透视规律!德扑圈透视(透视)透... 透视规律!德扑圈透视(透视)透视(好像是有挂)1、完成德扑圈透视透视辅助安装,帮助玩家取得所有比赛的...
透视攻略!aapoker ai... 透视攻略!aapoker ai插件(透视)插件(好像有挂)1、操作简单,无需注册,只需要使用手机进行...
透视脚本!德扑圈有透视吗(透视... 透视脚本!德扑圈有透视吗(透视)透视辅助软件(一直是有挂)1、上手简单,内置详细流程视频教学,新手小...
透视免费!aapoker脚本(... 透视免费!aapoker脚本(透视)免费透视脚本(都是存在有挂);1、下载好aapoker脚本辅助软...
透视辅助!德普之星透视辅助软件... 透视辅助!德普之星透视辅助软件是真的吗(透视)透视辅助软件(切实真的是有挂);运德普之星透视辅助软件...
透视规律!aapoker安装包... 透视规律!aapoker安装包怎么使用(透视)透视软件(一贯有挂)1、aapoker安装包怎么使用a...
透视透视!德普之星的辅助工具介... 透视透视!德普之星的辅助工具介绍(透视)私人局辅助免费(一直有挂);1、让任何用户在无需德普之星的辅...
透视透视!aapoker万能辅... 透视透视!aapoker万能辅助器(透视)脚本(好像真的是有挂)1、让任何用户在无需aapoker万...