sách gpt4 ai đã đi

angular - 进行 Angular 内容投影的现代方法是什么?

In lại 作者:行者123 更新时间:2023-12-05 06:32:10 28 4
mua khóa gpt4 Nike

我发现了很多嵌入/内容项目的旧方法,并且我遵循了在这里找到的最新方法(我假设):https://blog.angular-university.io/angular-ng-content/

我正在尝试在另一个组件的模式中包含另一个组件 html 文件。它们是兄弟组件,而不是父/子组件,这就是我认为它不起作用的原因。

谁能引导我朝着正确的方向前进?

对话框 html:


Title here








Actions here

对话框组件:

import {Component, OnInit} from '@angular/core';
import {MatDialog,
MatDialogRef,
MAT_DIALOG_DATA} from '@angular/material';

@Thành phần({
selector : 'test-dialog',
templateUrl : 'test-dialog.html',
styleUrls : ['./test-dialog.scss']
})
export class Test implements OnInit
{
constructor(public dialog: MatDialog) {}

ngOnInit(){}
}

test.html,我想包含的内容:


I want to include this content

测试组件:

import {Component, OnInit} from '@angular/core';
import {Router} from '@angular/router';

@Thành phần({
selector : 'test-component',
templateUrl : './test.html'
})

export class TestComponent implements OnInit
{

constructor(public router: Router) {}

ngOnInit(){}
}

编辑:我也已经在我想要包含的模块中包含了 CUSTOM_ELEMENTS_SCHEMA

1 Câu trả lời

我在 friend 的帮助下回答了这个问题。

我只是将选择器包含在 HTML 中,就像您放置组件时所做的那样:





不同之处在于它是兄弟组件,您必须导入模块。如果您导入该组件,Angular 会提示您导入它两次(一次在对话框模块中,一次在测试模块中)。

import {TestModule} from '../test/test.module';

@NgModule({
imports: [
TermsOfServiceModule
],

并且在 test.module 中你必须导出组件

exports: [
TestComponent
],

有点棘手的细微差别,我希望将来能对其他人有所帮助。

关于angular - 进行 Angular 内容投影的现代方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51430160/

28 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com