如何在Angular模板中使用 $ any()类型转换函数?
在角度文档中- https://angular.io/guide/template-syntax#the-any-type-cast-function 给出了一些描述和示例,但还不清楚。
有一个这样的例子-
<p>The item's undeclared best by date is: {{$any(item).bestByDate}}</p>
答案 0 :(得分:1)
只需用$any()
包装一个变量。不需要其他代码。
component.ts
export class AppComponent {
val = { name: 'foobar' }
}
component.html
<p>
{{ $any(val).name }}
</p>
stackblitz:https://stackblitz.com/edit/angular-qivjym
答案 1 :(得分:0)
接受的答案给出的例子没有显示CREATE OR REPLACE FUNCTION Get_Warnings RETURN SYS_REFCURSOR IS
v_recordset SYS_REFCURSOR;
JsonArray VARCHAR2(32767);
arrWarnings VARCHAR2(1000);
v_sql VARCHAR2(32767);
v_keys VARCHAR2(32767);
v_cols VARCHAR2(32767);
BEGIN
JsonArray :='[
{
"partialSuccessWarning": {
"VS-548986": [
"aaa"
],
"VS-548984": [
"bbb"
],
"VS-548982": [
"ccc"
]
}
}
]';
arrWarnings := JSON_QUERY(JsonArray, '$');
WITH t(JA) AS
(
SELECT JSON_QUERY(JsonArray, '$[*]."partialSuccessWarning"')
FROM dual
), t2 AS
(
SELECT REGEXP_REPLACE( REGEXP_SUBSTR( JA , '[^[]+',1,level ), '(.*")(\S+)(":.*)', '\2') AS keys, level AS lvl
FROM t
CONNECT BY level <= REGEXP_COUNT( JA, '\["' )
)
SELECT LISTAGG( '"'||keys||'"',',') WITHIN GROUP (ORDER BY lvl),
LISTAGG( '"'||keys||'" VARCHAR2(1000) PATH ''$."'||keys||'"[*]''',',') WITHIN GROUP (ORDER BY lvl)
INTO v_keys, v_cols
FROM t2;
v_sql :=
'SELECT '||v_keys||
' FROM dual
CROSS JOIN JSON_TABLE(:Warnings,
''$'' COLUMNS(NESTED PATH ''$[*]."partialSuccessWarning"''
COLUMNS('||v_cols||')
)
)';
OPEN v_recordset FOR v_sql USING arrWarnings;
RETURN v_recordset;
END;
/
背后的真正原因
$any
*ts
<p> {{obj.prop1}}</p>
<!--
This will throw an error without $any() because newProp is not part of typeof obj.
<p> {{obj.newProp}}</p>
-->
<p> {{$any(obj).newProp}}</p>
https://stackblitz.com/edit/angular-ivy-aofufm?file=src%2Fapp%2Fapp.component.html