我有一个简单的项目,显示一个 Ionic 段,其中有一个 Chart.js 条形图。我显示图表本身没有问题,但尝试将图表 HTML 放入 Ionic 段中会出现以下错误:
ERROR TypeError: Cannot read property 'nativeElement' of undefined
at HomePage.webpackJsonp.203.HomePage.ionViewDidLoad (home.ts:19)
Run Code Online (Sandbox Code Playgroud)
如果我只是将<canvas #barcanvas></canvas>其移动并放置在 .html 文档中的几乎任何其他位置,图表就会很好地显示,但不会显示在 Ionic 段元素内。
首页.html
<ion-header>
<ion-navbar>
<ion-title>
Ionic Blank
</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<div padding>
<ion-segment [(ngModel)]="pet">
<ion-segment-button value="kittens">
Kittens
</ion-segment-button>
<ion-segment-button value="puppies">
Puppies
</ion-segment-button>
</ion-segment>
</div>
<div [ngSwitch]="pet">
<ion-list *ngSwitchCase="'puppies'">
puppies...
<canvas #barcanvas></canvas>
</ion-list>
<ion-list *ngSwitchCase="'kittens'">
kittens...
</ion-list>
</div>
</ion-content>
Run Code Online (Sandbox Code Playgroud)
主页.ts
import { Component, ViewChild } from '@angular/core';
import { NavController } from …Run Code Online (Sandbox Code Playgroud) 我在 Angular 中有一个分页演示应用程序。我希望能够导航到像http://localhost:4200/page/:number. URL 在浏览器的 URL 地址栏中似乎正在更改,但我必须在浏览器的 URL 地址栏中按 Enter 键才能实际导航到 URL 并更改 HTML 表上的数据。
Stackblitz 在这里:https ://stackblitz.com/edit/angular-225jrs (HttpErrorResponse不是问题的一部分,但我不知道如何在 Stackblitz 中解决这个问题)。这是我的代码:
page.component.html:
<span *ngFor="let x of fakeArray; let index = index">
<button type="button" class="btn btn-primary" (click)="goToPage(index)">{{ index + 1 }}</button>
</span>
<br><br>
<table class="table">
<thead>
<tr>
<th>Alue-ID</th>
<th>Kunta</th>
<th>Lääni</th>
<th>Maakunta</th>
<th>Seutukunta</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let municipality of municipalities">
<td>{{ municipality.alue_id }}</td>
<td>{{ municipality.kunta }}</td>
<td>{{ municipality.laani }}</td>
<td>{{ municipality.maakunta }}</td>
<td>{{ municipality.seutukunta }}</td>
</tr> …Run Code Online (Sandbox Code Playgroud) 我收到以下 CORS 消息:
Access to XMLHttpRequest at 'http://localhost:8080/ottoautomaatitv2/webservice?postitoimipaikka=mikkeli'
from origin 'http://localhost:4200' has been blocked by CORS policy:
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Run Code Online (Sandbox Code Playgroud)
我尝试解决此问题的方法是添加CORS 过滤器,但这并没有解决问题。
<filter>
<filter-name>CorsFilter</filter-name>
<filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>CorsFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Run Code Online (Sandbox Code Playgroud)
我解决这个问题的唯一方法是使用带有--user-data-dir="C:/Chrome dev session" --disable-web-security目标的 Google Chrome,但这对我来说并不理想。如何Access-Control-Allow-Origin在 Apache Tomcat 上启用?
嘿伙计们,我是新的 ionic 程序员,我目前正在开发一个使用 youtube api(显示来自单个频道的视频)的应用程序。我遵循了一个教程,我和他做了同样的事情,但是我的出现了这个错误。
The pipe 'youtube' could not be found
Run Code Online (Sandbox Code Playgroud)
即使我按照教程所示创建并导入了 youtube 管道。这些是我的代码
这是我的 app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouteReuseStrategy } from '@angular/router';
import {HttpModule} from '@angular/http';
import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';
import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
import {YoutubePipe} from './youtube.pipe';
@NgModule({
declarations:
[AppComponent, YoutubePipe],
entryComponents: [], …Run Code Online (Sandbox Code Playgroud)