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

  

相关内容

热门资讯

透视解迷!wpk透视最怕三个东... 透视解迷!wpk透视最怕三个东西(透视)wepoker辅助器怎么弄,教程手筋(的确有挂)-哔哩哔哩1...
透视关于!福建大菠萝万能辅助器... 透视关于!福建大菠萝万能辅助器(透视)pokermaster破解版,教程策略(有挂攻略)-哔哩哔哩1...
透视解谜!aapoker透视插... 透视解谜!aapoker透视插件(透视)约局吧德州透视,教程诀窍(有挂解惑)-哔哩哔哩约局吧德州透视...
透视有挂!wepoker辅助器... 透视有挂!wepoker辅助器官方(透视)pokemmo手机辅助软件,教程方针(有挂解惑)-哔哩哔哩...
透视普及!德州hhpoker脚... 透视普及!德州hhpoker脚本(透视)约局吧德州有挂吗,教程秘籍(有挂技术)-哔哩哔哩1.约局吧德...
透视专业!佛手大菠萝辅助(透视... 透视专业!佛手大菠萝辅助(透视)we poker游戏下,教程积累(有挂讲解)-哔哩哔哩1、佛手大菠萝...
透视解密!xpoker辅助助手... 透视解密!xpoker辅助助手(透视)wepoker辅助器如何使用,教程手册(有挂猫腻)-哔哩哔哩1...
透视开挂!wpk辅助是什么(透... 透视开挂!wpk辅助是什么(透视)德扑圈透视挂,教程要领(确实有挂)-哔哩哔哩所有人都在同一条线上,...
透视专业!sohoo poke... 透视专业!sohoo poker辅助器(透视)wejoker黑侠辅助器,教程教程书(的确有挂)-哔哩...
透视辅助!aapoker公共底... 透视辅助!aapoker公共底牌(透视)wepoker透视脚本免费app,教程诀窍(有挂技巧)-哔哩...