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私人辅助器,微乐手游脚本辅助,辅助透视(揭秘有挂)-哔哩哔哩1、进入到wepok...
脚本开挂!aapoker怎么开... 您好,这款游戏可以开挂的,确实是有挂的,需要了解加去威信【485275054】很多玩家在这款游戏中打...
透视教学!wpk辅助,微乐陕西... 透视教学!wpk辅助,微乐陕西小程序辅助,详情透视(有挂秘笈)-哔哩哔哩wpk辅助是不是有人用挂微扑...
脚本透视!德普之星透视辅助插件... 脚本透视!德普之星透视辅助插件,德普之星辅助软件(透视)好像真的有攻略(哔哩哔哩)1、下载好脚本下载...
有了最新消息!uupoker有... 有了最新消息!uupoker有透视吗,微乐陕西麻将破解,总结脚本(有挂教学)-哔哩哔哩1、uupok...
透视辅助!aapoker透视方... 透视辅助!aapoker透视方法,aapoker怎么提高中牌率(透视)其实存在有工具(哔哩哔哩);1...
透视数据!hhpoker辅助器... 透视数据!hhpoker辅助器视频,微乐家乡自建房辅助app,透视透视(有挂总结)-哔哩哔哩1、游戏...
透视揭露!wepoker破解器... 透视揭露!wepoker破解器,wepoker游戏安装教程(透视)果然是真的神器(哔哩哔哩)1、完成...
透视脚本!如何判断wpk辅助软... 透视脚本!如何判断wpk辅助软件的真假,微乐手游微乐辅助免费,揭幕透视(今日头条)-哔哩哔哩1、打开...
脚本科普!wepoker好友房... 脚本科普!wepoker好友房开挂,wepoker透视脚本免费app(透视)都是真的有软件(哔哩哔哩...