小编car*_*los的帖子

在{{}}(Curly Brackets)中使用函数调用是一个好习惯吗?

在{{}}(Curly Brackets)中使用函数调用是一个好习惯吗?

有没有办法做到这一点?例如,在组件内(可能使用ngOnChanges或类似的......)

模板

<div class="container">
    {{ bootstrap() }}
    {{ validate() }}  
    <textarea class="form-control">{{ fullHtml }}</textarea>
    <button (click)="copy()" class="btn btn-primary">Click to Copy HTML</button>
    <textarea class="form-control">{{ validator }}</textarea>
    <button (click)="copy()" class="btn btn-warning">Click to Copy Validate</button>

    <button class="btn btn-danger" (click)="add()">Add page and input</button>
</div>
Run Code Online (Sandbox Code Playgroud)

零件

class HomeComponent {
    fullHtml = "";
    validator = "";
    pages = [{
        "name": "Page 1"
    },{
        "name": "Page 2"
    }];

    inputs = [{
        "name": "input_1",
        "required": true
    },{
        "name": "input_2",
        "required": false
    }];

    public bootstrap() …
Run Code Online (Sandbox Code Playgroud)

javascript angular

14
推荐指数
2
解决办法
1134
查看次数

按顺序运行多个可观察量

我想在单个中链接多个可观察量,并在管道链中进一步保留先前的值。

每个可观察量必须按顺序运行(一个接着一个,例如:如果第一个可观察量完成,则必须转到下一个)并且顺序很重要。我不想并行订阅它们(就像forkJoin一样)

输出必须向我提供用户信息、手机、地址和电子邮件。

我可以用switchmap来做到这一点,这种方法确实有效;但有更好的方法吗?

只是一个虚拟示例:

    this.userService.getUser(id)
    .pipe(
        switchMap(userResponse => {
            return this.cellphoneService.getCellphones(userResponse.id)
                .pipe(
                    map(cellphonesResponse => [userResponse, cellphonesResponse])
                )
        }),
        switchMap(([userResponse, cellphonesResponse]) => {
            return this.emailService.getEmails(userResponse.id)
                .pipe(
                    map(emailResponse => [userResponse, cellphonesResponse, emailResponse])
                )
        }),
        switchMap(([userResponse, cellphonesResponse, emailResponse]) => {
            return this.addressService.getAddresses(userResponse.id)
                .pipe(
                    map(addressResponse => [userResponse, cellphonesResponse, emailResponse, addressResponse])
                )
        }),
    ).subscribe(response => console.log(response))
Run Code Online (Sandbox Code Playgroud)

rxjs

5
推荐指数
1
解决办法
4878
查看次数

TypeScript 接口 [key: string]

我正在尝试编写一个接口,但它不断弹出一个错误:

"Property 'success' of type 'boolean' is not assignable to string index type 'PageableLaravel'

export interface PageableLaravel {
    path: string;
    current_page: number;
    from: number;   
}


export interface Pageable {
    success: boolean; // <-"Property 'success' of type 'boolean' is not assignable to string index type 'PageableLaravel'
    message: string; // "Property 'message' of type 'string' is not assignable to string index type 'PageableLaravel'
    [key: string]: PageableLaravel
}
Run Code Online (Sandbox Code Playgroud)

[key: string]会随时更改,例如:下面是从API返回的JSON的例子

{
    success: true,
    message: 'success',
    pages: {//<-key name always will change …
Run Code Online (Sandbox Code Playgroud)

typescript

1
推荐指数
1
解决办法
7485
查看次数

标签 统计

angular ×1

javascript ×1

rxjs ×1

typescript ×1