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

  

相关内容

热门资讯

交流学习经验!sohoo开挂辅... 交流学习经验!sohoo开挂辅助,wepoker脚本,详细教程(有挂方法)1、不需要AI权限,帮助你...
透视软件!拱趴大菠萝辅助神器(... 透视软件!拱趴大菠萝辅助神器(透视)其实有挂(详细辅助必胜教程)1、这是跨平台的黑科技,在线的操作超...
技术分享!xpoker辅助器,... 技术分享!xpoker辅助器,pokerworld破解版下载,切实教程(有挂辅助);大神普及一款德州...
透视挂透视!hhpoker有辅... 透视挂透视!hhpoker有辅助吗(透视)都是是真的有挂(详细辅助可靠教程)1、机器人多个强度级别选...
玩家必用!wepoker私人局... 玩家必用!wepoker私人局辅助器怎么用,哈糖大菠萝软件下载,力荐教程(有挂技巧)是由北京得wep...
透视透视!云扑克有透视吗(透视... 透视透视!云扑克有透视吗(透视)原来存在有挂(详细辅助玩家教程)1)辅助挂:进一步探索辅助透视大陆,...
总算了解!we-poker靠谱... 总算了解!we-poker靠谱吗,we-poker辅助器,2025新版(有挂攻略);支持2-10人实...
透视能赢!hhpoker底牌透... 透视能赢!hhpoker底牌透视脚本(透视)本来是真的有挂(详细辅助透明挂教程);1、超多福利:超高...
揭秘几款!哈糖大菠萝破解器,p... 1、揭秘几款!哈糖大菠萝破解器,pokermaster破解版,插件教程(有挂辅助);详细教程。2、哈...
透视中牌率!pokemmo辅助... 透视中牌率!pokemmo辅助器手机版下载(透视)本来是真的有挂(详细辅助AI教程)1、机器人多个强...