当我们#
用于在Python中插入注释时,Python如何采用:
# -*- coding: utf-8 -*-
Run Code Online (Sandbox Code Playgroud)
不同?
目前的官方文档仅显示如何动态更改标记内的组件<ng-template>
.https://angular.io/guide/dynamic-component-loader
我想实现的是,让我们说我有3个部分组成:header
,section
,并footer
具有以下选择:
<app-header>
<app-section>
<app-footer>
Run Code Online (Sandbox Code Playgroud)
再有6个按钮,这将增加或删除每个组件:Add Header
,Add Section
,和Add Footer
当我点击时Add Header
,页面将添加<app-header>
到呈现它的页面,因此页面将包含:
<app-header>
Run Code Online (Sandbox Code Playgroud)
然后如果我点击Add Section
两次,该页面现在将包含:
<app-header>
<app-section>
<app-section>
Run Code Online (Sandbox Code Playgroud)
如果我点击Add Footer
,页面将包含所有这些组件:
<app-header>
<app-section>
<app-section>
<app-footer>
Run Code Online (Sandbox Code Playgroud)
是否有可能在Angular中实现这一目标?请注意,这ngFor
不是我正在寻找的解决方案,因为它只允许向页面添加相同的组件,而不是不同的组件.
编辑:ngIf和ngFor不是我正在寻找的解决方案,因为模板已经预先确定.我正在寻找的东西就像一堆组件或一组组件,我们可以轻松地添加,删除和更改数组的任何索引.
编辑2:为了使它更清楚,让我们有另一个例子说明为什么ngFor不起作用.假设我们有以下组件:
<app-header>
<app-introduction>
<app-camera>
<app-editor>
<app-footer>
Run Code Online (Sandbox Code Playgroud)
现在,这里有一个新组件,ngIf
用户希望在其间插入ngFor
.ngFor只有在我想要循环遍历的同一个组件时才有效.但是对于不同的组件,ngFor在这里失败了.
我有一个如下所示的集合:
{
"_id": 1,
"user": "xyz",
"sentence": "I watch movies and web series.",
"nouns": [
"movies",
"web series"
],
"verbs": [
"watch"
]
},
{
"_id": 2,
"user": "xyz",
"sentence": "movies are good way to relax",
"nouns": [
"movies"
],
"verbs": [
"relax"
]
}
Run Code Online (Sandbox Code Playgroud)
有两个数组字段,nouns
并verbs
为每个用户的句子。我想按user
字段对文档进行分组,并分别计算nouns
和verbs
数组中每个不同元素的数量。我已经尝试了以下查询(如果你不想,你可以跳到这个聚合的最后阶段):
{
"_id": 1,
"user": "xyz",
"sentence": "I watch movies and web series.",
"nouns": [
"movies",
"web series"
],
"verbs": [
"watch"
]
},
{ …
Run Code Online (Sandbox Code Playgroud) 我将一个变量声明x
为
public x : 0;
Run Code Online (Sandbox Code Playgroud)
而不是将其初始化为 0
认为我已经正确地声明了它,我将它初始化为
this.x = 5;
Run Code Online (Sandbox Code Playgroud)
我在上面的行中遇到错误,其中读取
Type '5' is not assignable to type '0'.ts(2322)
Run Code Online (Sandbox Code Playgroud)
谁能告诉,为什么会这样?
我正在做一个带有角度的网站,我试图将两个数字相加并在 a 中显示它们< div >
,但我不知道如何管理精度。
例如,使用以下代码:
网页:
<div>{{sum}}</div>
Run Code Online (Sandbox Code Playgroud)
打字稿:
sum = 9.9 + 1.3
Run Code Online (Sandbox Code Playgroud)
11.200000000000001
当我想展示时,网站展示了价值11.2
我已经看到管理浮动操作的方法是使用toFixed(1)
,然后我得到了期望11.2
。但是,如果我使用, 来执行我想要获取的toFixed(1)
操作10.0 + 1.0
11.0
11
所以我想要的是当有小数时有一位小数的数字,当没有小数时没有小数的数字
我想知道是否有可能“混合”mat-select
和mat-chip-list
。在 中chip-list
,我想显示从mat-select
.
如果是,我该怎么做?
请考虑以下情况:
案例 1:使用文字和变量初始化变量,我之前从未声明或初始化过这些变量。
var x = 10, i;
Run Code Online (Sandbox Code Playgroud)
当我打印 的值时x
,它会打印10
。我想知道,这在语法上是如何正确的?这是出乎意料的事情。这是一个错误吗?
案例 2:使用我之前声明或初始化过的变量和文字初始化变量。
var i = 10;
var x = i, 10;
Run Code Online (Sandbox Code Playgroud)
然后,我尝试了上面的方法,认为如果CASE 1可以工作,那么上面的方法也应该有效。但是,我很惊讶,它没有用。相反,它给出了一个错误:Uncaught SyntaxError: Unexpected number
。
CASE 3:初始化一个变量,有两个文字。
var x = 10, 10;
Run Code Online (Sandbox Code Playgroud)
我在上面尝试过,但它给我带来了同样的错误:Uncaught SyntaxError: Unexpected number
. 现在我很困惑。
CASE 4:初始化一个变量,有两个变量,我之前已经声明或初始化过。
var i = 10;
var j = 20
var x = i, j;
Run Code Online (Sandbox Code Playgroud)
上述案例给了我预期的结果,即10
.
但是,在上述所有情况之后,为什么即使首先,JavaScript 在语法上也允许这样做呢?也有一个我以前从未声明过的变量?我很困惑。有什么问题吗,比如一个错误?或者对此有什么解释吗?
笔记:
我的 angular 应用程序有一个奇怪的问题,我刚刚将 AngularFire 添加到我的项目中,但是当我尝试将其安装时,它显示以下错误:
ERROR in nodae_modules/@angular/fire/angularfire2.d.ts(37,49): error TS2344: Type 'T[K]' does not satisfy the constraint '(...args: any[]) => any'.
node_modules/@angular/fire/angularfire2.d.ts(40,49): error TS2344: Type 'T[K]' does not satisfy the constraint '(...args: any[]) => any'.
node_modules/@angular/fire/angularfire2.d.ts(48,78): error TS2344: Type 'T[K]' does not satisfy the constraint '(...args: any[]) => any'.
node_modules/@angular/fire/angularfire2.d.ts(48,107): error TS2344: Type 'T[K]' does not satisfy the constraint '(...args: any[]) => any'.
node_modules/@angular/fire/angularfire2.d.ts(50,75): error TS2344: Type 'T[K]' does not satisfy the constraint '(...args: any[]) => any'.
node_modules/@angular/fire/angularfire2.d.ts(50,96): error TS2344: …
Run Code Online (Sandbox Code Playgroud) typescript ×5
angular ×4
javascript ×2
angularfire ×1
angularfire2 ×1
arrays ×1
comments ×1
encoding ×1
html ×1
mongodb ×1
python ×1