- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
当我这样做时:
ionic generate component my-component
创建了这个文件夹结构:
components
my-component
my-component.ts
my-component.scss
my-component.html
components.module.ts
我想在页面中使用这个组件。我不打算在 Ionic 3 中使用新的延迟加载机制,但我不介意。最简单的方法,我只想使用该组件!顺便说一句,我的页面本身没有模块,这是页面的文件夹结构:
pages
somepage
somepage.ts
somepage.scss
somepage.html
现在回到组件:我在模板中使用自定义 ionic 组件 (ion-grid)。所以 my-component.html
看起来像这样:
<ion-grid></ion-grid>
该行在 VS Code 中以红色突出显示。错误内容如下:
'ion-grid' is not a known element:
1. If 'ion-grid' is an Angular component, then verify that it is part of this module.
2. If 'ion-grid' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
这应该根据一百个帖子和问题解决,方法是将 IonicModule
和 CommonModule
添加到 components.module.ts
中:
@NgModule({
declarations: [MyComponent],
imports: [
CommonModule ,
IonicModule
],
exports: [MyComponent]
})
export class ComponentsModule {}
但这当然不能解决错误。
第二个问题是页面无法识别新的自定义元素。 somepage.html
中的这一行:
<my-component></my-component>
也以红色突出显示并显示此错误:
'my-component' is not a known element:
1. If 'my-component' is an Angular component, then verify that it is part of this module.
2. If 'my-component' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
我最初虽然必须将组件模块添加到 app.module.ts
:
@NgModule({
declarations: [
MyApp,
SomePage
],
imports: [
...
ComponentsModule
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
SomePage
],
providers: [...]
})
export class AppModule {}
但这并没有解决任何问题。在阅读了 2 个小时的大量帖子后,我意识到可怕的 components.module.ts
是用于延迟加载的,我必须为页面添加一个模块,所以我放弃并尝试添加组件直接添加到 app.module.ts
:
@NgModule({
declarations: [
MyApp,
SomePage,
MyComponent
],
imports: [
...
MyComponent
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
SomePage
],
providers: [...]
})
export class AppModule {}
我也尝试过其他组合,但没有任何效果。看在上帝的份上,这是在 Angular 中最容易做的事情,在 Ionic 2 中也很容易。你到底需要做什么才能在 Angular 3 中使用组件?
最佳答案
我终于解决了这两个问题。
问题 #1:如何让应用程序识别组件:
删除components.module.ts
。下次生成组件时,使用阻止 ionic 再次创建此文件的标志:
ionic 生成组件 mycomponent --no-module
手动将组件添加到 app.module.ts
中,仅在 declarations
中:
@NgModule({
declarations: [
MyApp,
SomePage,
MyComponent
],
...
})
export class AppModule {}
问题 #2:如何在组件模板中使用 Ionic 组件:
您不需要做任何特别的事情。只需使用它们。在将组件添加到 app.module.ts
之前,我遇到了一些错误,并且 Visual Studio Code 没有从“问题”选项卡中删除错误。但该应用程序有效。我刚刚重新启动 VS Code,错误不再出现。显然这是 VS Code 的一个已知问题,您需要重新启动它以消除旧错误。
关于angular - ionic 3 : How to add a component,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49814549/
我有以下代码。我无法理解应如何实现 ProjectCardDescription 组件,以便能够在 ProjectCard 组件中传递其描述 我尝试过这个,但得到一个空组件: import React
我们正试图从 styled-components 项目中找出以下问题的原因:https://github.com/styled-components/styled-components/issues/
将所有文件从 jsx 更改为 tsx 后,出现此错误: ./src/components/index.js Module not found: Can't resolve './Header' in
我正在努力遵循以下 vuejs 应用场景动态组件 + 异步组件模式。一切正常,但仍然只有一个问题:我怎样才能访问通过传入的 Prop 数据 请看现场 fiddle : https://jsfiddl
我已经明白了Difference between React Component and React Element , 使用 JSX 基本上调用 React.createElement它返回一个元素
我最近开始使用 JSX 元素语法而不是调用函数,因为它使代码更漂亮。但看起来又不太一样。令人惊讶的是,因为在 App.js 中,函数调用会导致无限循环(并引发错误),但 JSX 元素可以工作。在 Da
通过少量渲染来构建嵌套组件系统的好方法是什么?请参阅下面带有主要问题(“如何...”)的所需代码: tab.vue(子组件) export default {
我正在编写一个轻量级游戏引擎,并且在为它做一些研究的同时,我遇到了许多令人信服的文章,它们提倡通过“组件集合”模型而不是“从具体类继承”模型来实现游戏对象。有很多优点: 可以使用数据组合对象 驱动设计
类型‘AbstractControl’上不存在属性‘Controls’。
考虑以下示例: function Travel(props) { return ( ) } function Welcom
我刚刚加入了一个 React Native 项目,在那里我经常看到扩展 React.Component 和 Component 本身的类。 示例: 类 SomeView 扩展了 React.Compo
我见过两种访问 Component 的方法: import React from 'react'; class Foo extends React.Component { ... } 和 im
我有一个库 jar,我想将其提供给许多应用程序。我想要的行为是在库中创建一个通用的 spring 组件类。如果在应用程序中,没有扩展相同的组件,则使用公共(public)组件;如果它在应用程序中扩展,
所以我正在制作一个游戏,我有 EnemyAI 以及 player,它们都扩展了 JPanel。世界有一个 null 布局,所以我正在使用 setBounds(); 来“移动”(我实际上只是移动世界图像
在 styled-component 中,您如何决定是应该使用插值函数来修改组件(通过传递 props )还是扩展现有组件。例如: const Button = styled.button`
我搜索并获取了以下信息。 请添加您的信息 h:commandbutton 与 a4j:commandButton 相同,唯一的区别是 a4j:commandButton 有额外的 ajax 请求。 a
我目前在一个项目中,我们有一个动态“表单”/内容模型,其中我们有一个包含字段和占位符的模块,占位符可以包含更多模块,为我们提供递归/灵活的数据模型. 现在为了渲染这个,我们创建了一个组件来渲染模块,动
我是 React 的新手,正在尝试设置一个 Bootstrap 模式来显示警报消息。 在我的父 App.js 文件中,我有一个错误处理程序,它向 Modal.js 组件发送一个触发模态显示的 Prop
通过 background-color:red 获得主页组件写入其 scss,然后使用 background-color:green 获取用户组件写入它的 scss。我启动我的应用程序,我在家,背景是
我有这个基本的应用程序,其中一些组件具有公共(public) load 方法。对于某些操作,我想在当前 svelte:component 上调用该方法,但我不知道如何获取对组件实例的引用。如何做到这一
我是一名优秀的程序员,十分优秀!