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

  

相关内容

热门资讯

玩家必备攻略!德州局透视,德州... 玩家必备攻略!德州局透视,德州局脚本,科技教程(有挂攻略);最新版2024是一款经典耐玩的益智游戏,...
盘点一款!wepoker透视底... 盘点一款!wepoker透视底牌脚本,hhpoker有辅助吗,总结教程(有挂教程);玩家必备必赢加哟...
一分钟了解!wepoker有机... 一分钟了解!wepoker有机器人吗,wepoker好友局透视,2025新版教程(有挂透明)1、很好...
玩家必备教程!wepoker安... 玩家必备教程!wepoker安装教程,wepoker分析,解密教程(有挂攻略)科技教程也叫必备教程,...
热点推荐!竞技联盟辅助插件,w... 热点推荐!竞技联盟辅助插件,wepoker破解器有用吗,黑科技教程(有挂教程)1、不需要AI权限,帮...
总算了解!wepoker有没有... 1、总算了解!wepoker有没有透视方法,hhpoker的辅助是真的吗,我来教教你(有挂教程);详...
新手必备!wepoker分析,... 新手必备!wepoker分析,wepoker黑侠破解,透明教程(有挂透明);wepoker黑侠破解软...
信息共享!德扑HHpoker有... 信息共享!德扑HHpoker有挂吗,约局吧辅助器,攻略方法(有挂神器)科技教程也叫必备教程,这是一款...
总算清楚!hhpoker怎么破... 总算清楚!hhpoker怎么破解,aapoker ai插件,实用技巧(有挂教程);致您一封信;亲爱h...
重大通报!xpoker怎么作弊... 重大通报!xpoker怎么作弊,wepoker好友局透视,第三方教程(有挂教程);支持2-10人实时...