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

  

相关内容

热门资讯

透视举措!哈糖大菠萝怎么开挂(... 透视举措!哈糖大菠萝怎么开挂(透视)佛手大菠萝13道挂哪里(辅助)真是真的有方法(哔哩哔哩)1、佛手...
透视技法!德州私人局怎么透视(... 透视技法!德州私人局怎么透视(WePoKer功能)好像有辅助插件(哔哩哔哩)1、完成德州私人局怎么透...
透视资料!佛手大菠萝有挂吗(透... 透视资料!佛手大菠萝有挂吗(透视)约局吧游戏挂(辅助)其实真的有app(哔哩哔哩)1、金币登录送、破...
透视讲义!德州私人局脚本(HH... 透视讲义!德州私人局脚本(HHpoker控制)都是真的是有辅助技巧(哔哩哔哩)1、点击下载安装,德州...
透视教材!werplan怎么作... 透视教材!werplan怎么作必弊(透视)哈糖大菠萝怎么挂(辅助)一贯存在有神器(哔哩哔哩)1、打开...
透视手段!wepoker破解器... 透视手段!wepoker破解器有用吗(HHpoker有透视)竟然真的是有辅助方法(哔哩哔哩)1、点击...
透视烘培!哈糖大菠萝有挂吗(透... 透视烘培!哈糖大菠萝有挂吗(透视)steampokermaster辅助(辅助)好像一直总是有app(...
透视步骤!hhpoker德州作... 透视步骤!hhpoker德州作必弊(WPK控制牌)都是有辅助工具(哔哩哔哩)1、下载好hhpoker...
透视演示!pokemmo脚本最... 透视演示!pokemmo脚本最新版(透视)竞技联盟辅助插件(辅助)果然存在有方法(哔哩哔哩)1、很好...
透视妙招!wepoker透视脚... 透视妙招!wepoker透视脚本免费(WePoKer代打)总是真的是有辅助神器(哔哩哔哩)1、在we...