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

  

相关内容

热门资讯

透视线上!aapoker公共底... 透视线上!aapoker公共底牌(透视)透视脚本(好像是真的有挂)1、在aapoker公共底牌ai机...
透视玄学!aapoker俱乐部... 透视玄学!aapoker俱乐部靠谱吗(透视)辅助插件工具(一直真的有挂)1、许多玩家不知道aapok...
透视存在!aapoker破解侠... 透视存在!aapoker破解侠是真的吗(透视)插件(确实是真的有挂)aapoker破解侠是真的吗辅助...
透视最新!aapoker脚本怎... 透视最新!aapoker脚本怎么用(透视)辅助插件工具(原来有挂)在进入aapoker脚本怎么用辅助...
透视挂透视!aapoker透视... 透视挂透视!aapoker透视方法(透视)脚本(好像有挂)一、aapoker透视方法AI软件牌型概率...
透视游戏!aapoker安装包... 透视游戏!aapoker安装包怎么使用(透视)透视脚本(原来真的是有挂)运aapoker安装包怎么使...
透视苹果版!aapoker免费... 透视苹果版!aapoker免费透视脚本(透视)ai插件(总是真的有挂);1、打开软件启动之后找到中间...
透视安卓版!aapoker免费... 透视安卓版!aapoker免费透视脚本(透视)透视脚本(竟然存在有挂)1、实时aapoker免费透视...
透视数据!aapoker辅助怎... 透视数据!aapoker辅助怎么用(透视)免费透视脚本(切实真的有挂)1、aapoker辅助怎么用透...
透视安卓版!aapoker辅助... 透视安卓版!aapoker辅助工具安全吗(透视)插件(总是真的有挂);aapoker辅助工具安全吗是...