Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 将两个参数传递给ng模型-Typescript_Angular_Typescript_Angular8 - Fatal编程技术网

Angular 将两个参数传递给ng模型-Typescript

Angular 将两个参数传递给ng模型-Typescript,angular,typescript,angular8,Angular,Typescript,Angular8,我是angular8的新手。 我有以下模板: <label class="pr-1 selectLabel" [title]="'alphOrder' | translate">{{'alphOrder' | translate}}</label> <ng-select class="w-25 p-3" placeholder="Select" [items]="(sortingField | async)?.alphOrder" [clearable]="fals

我是angular8的新手。
我有以下模板:

<label class="pr-1 selectLabel" [title]="'alphOrder' | translate">{{'alphOrder' | translate}}</label>
<ng-select class="w-25 p-3" placeholder="Select" [items]="(sortingField | async)?.alphOrder" [clearable]="false" [(ngModel)]="HERE" (change)="sortBy('titles', HERE)" [searchable]="false">
</ng-select>
{{'alphOrder'| translate}
在第一行中,我通过
翻译功能向
[title]
传递了一个键。
我想用
[(ng model)]
在第二行做同样的事情,传递两个参数的区别。
然后我想通过
函数将相同的参数传递给
sortBy
在这两种情况下,参数必须具有
translate
功能。
我想了解如何编写这样的东西,因为我从来不知道如何使用模板语法

实际上,translate是一个pip。 您的ng模型具有双向绑定。所以你不能用一个小点做双向绑定。 你必须把它分成两部分

  • 要查看绑定的模型
  • ngModelChange
下面是一些示例->

我会根据您的需要解决问题。
如果没有太多的元素,可以在模板中执行类似的操作(考虑到这些语言的所有
json
文件都是这样)​​您已经放置了所有相同的键):


对于您的模型,您需要在
TypeScript
代码中处理翻译。已经完成了。我只是想知道如何传递两个可翻译的参数,而不是一个…你不能,如果你正在更新模型,那么需要两个参数吗?如果你在两个变量中设置相同的值,你可以将它们作为一个变量。或者您可以使用
(更改)
功能设置多个变量
<ng-select (change)="sortBy(selection)" [(ngModel)]="selection" class="w-25 p-3" placeholder="Select" [clearable]="false" [searchable]="false">
    <ng-option>{{'author' | translate}}</ng-option>
    <ng-option>{{'title' | translate}}</ng-option>
    <ng-option>{{'date' | translate}}</ng-option>

    <!-- and you can continue to unwind elements if there are not too many ... -->

</ng-select>
export class myComponent {

    public val: string;

    sortBy(val) {
        console.log("Dropdown selection:", val);

        // do whatever you want with the translatable element 
    }
}