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

  

相关内容

热门资讯

透视规律!德普之星辅助器app... 透视规律!德普之星辅助器app,德普之星app安卓版破解版(透视)都是真的有挂(详细教程)-哔哩哔哩...
记者获悉!欢乐茶馆免费辅助,新... 记者获悉!欢乐茶馆免费辅助,新道游app下载,阶段教程(有挂分析)-哔哩哔哩小薇(辅助器软件下载)致...
透视黑科技!德普之星有辅助软件... 透视黑科技!德普之星有辅助软件吗,德普之星透视辅助插件(透视)其实是真的挂(讲解有挂)-哔哩哔哩亲,...
刚刚!一起温州辅助器,新蛮王辅... 刚刚!一起温州辅助器,新蛮王辅助器,课程教程(有挂教程)-哔哩哔哩1、每一步都需要思考,不同水平的挑...
透视了解!德普之星app安卓版... 透视了解!德普之星app安卓版破解版,德扑圈有透视吗(透视)好像是有挂(有挂分享)-哔哩哔哩德普之星...
今天上午!新道游科技透视免费版... 今天上午!新道游科技透视免费版下载网页,财神13游戏辅助器脚本,妙计教程(真的有挂)-哔哩哔哩1、新...
透视脚本!德普辅助软件,德普之... 透视脚本!德普辅助软件,德普之星怎么设置埋牌(透视)一直是真的挂(有挂教程)-哔哩哔哩德普之星怎么设...
透视线上!德普之星辅助器app... 透视线上!德普之星辅助器app,德扑圈透视(透视)果然是有挂(有挂方略)-哔哩哔哩1、这是跨平台的德...
不少玩家反映!微信小程序小南四... 不少玩家反映!微信小程序小南四川长牌辅助,微信小程序雀神麻将好运来,办法教程(有挂秘籍)-哔哩哔哩一...
透视安装!德普之星透视辅助软件... 透视安装!德普之星透视辅助软件下载,德普之星辅助器app(透视)都是真的有挂(有挂方法)-哔哩哔哩1...