2017-01-05 27 views
3

以下是我对离子页面内容:离子的看法是不是一个已知的元素

<ion-content padding class = ""view-content"> 
    <form> 
     [form content here...] 
    </form> 
    </ion-content> 

我的CSS文件:

.view-content { 
    background: url("background.jpg"); 

,但它不工作,我发现了以下错误:

Unhandled Promise rejection: Template parse errors: 
'ion-view' is not a known element: 
1. If 'ion-view' is an Angular component, then verify that it is part of this module. 
2. If 'ion-view' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schemas' of this component to suppress this message. (" 
[ERROR ->]<ion-view view-title="My Page"> 
<ion-content> 
Hello! 
") 

可以告诉我在这里做错了什么或如何解决这个问题。 我是新来的离子框架,事实上新的web开发。

+0

你使用离子型1还是离子型2? –

+0

请分享您的组件代码。 – JoeriShoeby

+0

离子视图是离子1中的一种成分,而不是离子2中的成分。 –

回答

2

离子的观点是在离子版本1的有效成分和版本不可2.

为了设定图像的背景可以设置一个CSS类和设置'背景”属性

<ion-content class="view-class"> 
Hello! 
</ion-content> 

在你对应的SCSS

.view-class { 
    background: url("path_to_image") 
} 

编辑:sample plunker

+0

我从昨天开始这样做,但它不起作用 –

+0

我可以设置背景颜色,但不是图像。 –

+0

你可以添加你的代码来质疑吗? –

0

离子视图不像它说的那样。删除 和

+0

任何想法如何添加背景作为离子2中的页面的图像? –

0

我不知道很多关于离子收盘,但似乎错误是在模块

<ion-view view-title="My Page"> 
    <ion-content> 
     Hello! 
    </ion-content> 
    </ion-view> 

根据错误,如果你正在使用ion-view或在您的应用程序的任何组件,比你必须添加成分主要模块。

与angular2类似,我们在app.module.ts文件中做了同样的处理,我们告诉角度哪些组件将在应用的负载上加载。

这样

@NgModule({ 
    declarations: [ 
    here component list, directives and pipes 
    ], 
    imports: [ 
    ion-view, etc..... 
    ], 
    providers: [CanActivateViaAuthGuard, GlobalService], 
    bootstrap: [AppComponent] 
}) 
export class AppModule { } 
+0

是来自Ionic Framework的指令,你的回答是错误的。 – JoeriShoeby

+0

好,所以你可以把你的指令放在decalration部分。这样对吗 ? –

0

从外观上来看,我认为你已经创建的页面或组件是在一个单独的模块。请将IonicModule导入添加到该模块,并将该模块导入到应用程序模块中。

import { NgModule } from "@angular/core"; 
import { ItemsComponent } from "./items/items"; 
import { ItemComponent } from "./item/item"; 
import { IonicModule } from "ionic-angular"; 

@NgModule({ 
    declarations: [ItemsComponent, ItemComponent], 
    imports: [IonicModule], 
    exports: [ItemsComponent, ItemComponent] 
}) 
export class ComponentsModule {} 
相关问题