小编Mac*_*ota的帖子

CORS Angular和SpringBoot-请求被阻止

我有一个似乎无法解决的问题。我想从我的网站发送http请求

角客户端:

const url = 'http://localhost:8080/api';
console.log(this.http.get(url).subscribe(data => this.greeting = data));
Run Code Online (Sandbox Code Playgroud)

到我使用CORS注释的SpringBoot后端:

@CrossOrigin(origins = "http://localhost:4200/", maxAge = 3600)
    @RequestMapping("/api/")
    public Map<String,Object> home() {
        Map<String,Object> model = new HashMap<String,Object>();
        model.put("id", UUID.randomUUID().toString());
        model.put("content", "Hello World");
        return model;
    }
Run Code Online (Sandbox Code Playgroud)

但我收到一个错误,该错误已被阻止,并始终将我重定向到登录名。

Failed to load http://localhost:8080/api: Redirect from 'http://localhost:8080/api' to 'http://localhost:8080/login' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access. 
Run Code Online (Sandbox Code Playgroud)

有办法改变吗?

我对此表示感谢或帮助。我想了解为什么会发生此问题。

spring spring-boot angular

9
推荐指数
2
解决办法
2万
查看次数

悬停在相应元素上时更改标记颜色 -&gt; Angular 4

当我将鼠标悬停在不同组件中的元素之一上时,我试图动态更改 google 标记的颜色。我仍在学习 Angular,我尝试使用 Observables 但没有任何成功。

我有main.view 存储所有卡片的组件(我称之为事件)。这是main-view.component.ts代码的一部分:

constructor( private eventService: EventsDataService) {
    }
      ngOnInit() {
        this.getEvents();
      }
Run Code Online (Sandbox Code Playgroud)

我正在注入从服务器获取卡片数据的服务,并使用getEvents方法使用 Observable 将其转换为 JSON 数据。然后我在html模板中使用 2 个 *ngFor 指令来迭代这些数据并填充卡片和标记。这是代码:

main-view.component.html

 <app-event-card *ngFor="let event of events; let i = index"></app-event-card>
  </section>
  <aside class="mapContainer"  [class.fixed]="fixed">
      <agm-map [class.fixed]="fixed"  [latitude]= "latitude"  [longitude]="longitude" >
        <agm-marker *ngFor="let event of events; let i = index"
        [latitude]= "event.location.coordinates[0]"
        [longitude]="event.location.coordinates[1]"
        label="{{event.price +'AUD'}}">
      </agm-marker>
      </agm-map>
  </aside>
Run Code Online (Sandbox Code Playgroud)

现在,当我将鼠标悬停在与标记相对应的一张卡片上时,我想更改标记的颜色或任何属性,但我不知道如何连接这两个组件的数据。

我将不胜感激有关此问题的任何帮助或提示。

谢谢

hover angular

5
推荐指数
2
解决办法
6024
查看次数

Create nested array in Javascript

I'm trying to convert my data from API to my needs. Would like to create a nested array from plain array. I would like to group elements by parentId property, if parentId would not exist I would put it as a root. id value is unique. Like so (raw data):

[
    {id: 1, name: 'sensor'},
    {id: 2, name: 'sensor', parent: 1},
    {id: 3, name: 'sensor', parent: 1},
    {id: 4, name: 'sensor', parent: 3},
    {id: 5, name: 'sensor'},
    {id: 6, name: …
Run Code Online (Sandbox Code Playgroud)

javascript

5
推荐指数
1
解决办法
106
查看次数

在 Material-UI React 中将鼠标悬停在复选框上时如何更改复选框样式和图标?

我在我的项目中使用material-ui,并且有一个红色的复选框。

当有人仅将鼠标悬停在复选框上时,我想显示选中的图标。

不悬停时它会隐藏。我似乎没有找到合适的选择器。我希望得到任何关于我能做些什么的建议。

html javascript css reactjs material-ui

5
推荐指数
1
解决办法
9249
查看次数

标签 统计

angular ×2

javascript ×2

css ×1

hover ×1

html ×1

material-ui ×1

reactjs ×1

spring ×1

spring-boot ×1