小编Boo*_*ong的帖子

ngFor(Angular 2)中的动态模板引用变量

如何在元素中声明动态 模板引用变量ngFor

我想使用ng-bootstrap中的popover组件,popover代码(带有Html绑定)如下所示:

<ng-template #popContent>Hello, <b>{{name}}</b>!</ng-template>
    <button type="button" class="btn btn-secondary" [ngbPopover]="popContent" popoverTitle="Fancy content">
    I've got markup and bindings in my popover!
</button>
Run Code Online (Sandbox Code Playgroud)

如何这些元素包装在里面ngFor

<div *ngFor="let member of members">
    <!-- how to declare the '????' -->
    <ng-template #????>Hello, <b>{{member.name}}</b>!</ng-template>
        <button type="button" class="btn btn-secondary" [ngbPopover]="????" popoverTitle="Fancy content">
        I've got markup and bindings in my popover!
    </button>
</div>
Run Code Online (Sandbox Code Playgroud)

嗯......任何想法?

angular-template ng-bootstrap angular

56
推荐指数
2
解决办法
3万
查看次数

Golang 通过 JSON 标签获取结构体的字段名称

我有一个结构:

type Human struct {
    Head  string  `json:"a1"`
    Body  string  `json:"a2"`
    Leg   string  `json:"a3"`
}
Run Code Online (Sandbox Code Playgroud)

如何通过提供 JSON 标记名称来获取结构的字段名称?大概是这样的:

fmt.Println(getFieldName("a1")) // "Head"
fmt.Println(getFieldName("a2")) // "Body"
fmt.Println(getFieldName("a99")) // ""

func getFieldName(tag string) (fieldname string) {
    /* ... */
}
Run Code Online (Sandbox Code Playgroud)

我应该如何实现该getFieldName功能?我在网上看了,好像需要用到这个reflect包,嗯……有帮手吗?:)

go

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

如果路由到相同的参数,Angular 不会重新加载

article/:id每次单击按钮时我都想重新加载页面,Angular 能够在:id更改时重新加载页面,但是如果路由到 same :id,则它会忽略更改。

export class DocumentComponent {
    constructor(
        private activatedRoute: ActivatedRoute,
        private router: Router
    ) {}

    ngOnInit() {
        this.routeSubscription = this.activatedRoute.params.subscribe(params => {
            this.reloadPage(+params['id']);
        });
    }

    clickReload(id: number) {
        this.router.onSameUrlNavigation = 'reload';
        this.router.navigate(['article', id]);
    }
}
Run Code Online (Sandbox Code Playgroud)

当 params 改变时,observableparams将被触发,并被reloadPage()执行。但是,当我尝试重新加载相同的paramsAngular 时会忽略它,我该如何重新加载相同的param

article/123 --> article/456 [ok]
article/111 --> article/222 [ok]
article/666 --> article/666 [not ok, how?]
Run Code Online (Sandbox Code Playgroud)

我尝试使用onSameUrlNavigation,但它不起作用......我做错了什么吗?

angular

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

如何在浏览器中显示 Angular9 更改检测过程?

我有一个复杂的组件,其中包含许多 @Input() 和异步进程。我想优化组件,因此打算在我的组件上分析 Angular4 更改检测周期

我可以知道如何识别Angular4 更改检测系统是否正在被触发,以及 DOM 是否正在重新呈现

可能,使用console.log(...)?

通常,我希望类似(在浏览器控制台中):

Change-detection running... no changes... 1
Change-detection running... no changes... 2
Change-detection running... no changes... 3
Change-detection running... no changes... 4
Change-detection running... changed
No DOM rendering
Change-detection running... no changes... 5
Change-detection running... no changes... 6
Change-detection running... changed
DOM re-rendered
Change-detection running... no changes... 7
Change-detection running... no changes... 8
Run Code Online (Sandbox Code Playgroud)

我如何实现这一目标?或者你们如何优化 Angular4 的性能?还有其他方法吗?

angular

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

如何使用来自其他 Angular 组件的`templateref`?

如何templateRef从其他组件模板文件中使用?

我有BatmanComponentSpidermanComponent还有一个JokerComponent。其中一些具有类似的功能,因此我决定创建一个HumanComponent, 并将所有可重用的 HTML 代码放在该文件中,如下所示:

注意:HumanComponent永远不会使用,它只是一个包含所有默认模板的文件。

<!-- human.component.ts -->
<ng-template #eye>
    Eyes: {{ size }}
</ng-template>
<ng-template #body>
    Body: bust {{ x[0] }}, waist {{ x[1] }}, hip {{ x[2] }} 
</ng-template>
Run Code Online (Sandbox Code Playgroud)

我可以知道如何注入这些模板(来自human.component.ts)并在batman.component.ts.... 中使用它吗?

我知道我可以这样做:(仅模板代码被复制粘贴到蝙蝠侠、蜘蛛侠和小丑HTML 文件中时)

<!-- batman.component.ts -->
<ng-container *ngTemplateOutlet="eye; context: contextObj"></ng-container>

<ng-template #eye> ... </ng-template> <!-- need to copy/paste here, and use it locally -->
Run Code Online (Sandbox Code Playgroud)

我可以知道如何导出 templateRef …

angular

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

如何在Postgresql时间戳中存储Golang time.time?

我可以知道如何time.time在Postgresql中存储对象吗?

例如,SQL查询:

INSERT INTO "UserAccount" ("email", "login_time") VALUES ('human@example.com', 2017-12-12 00:58:26.9589451 +0800 +08 m=+1406.914186601)

我尝试使用loginTime := time.Now(),它给出了Postgresql不太懂的时间格式,例如2017-12-12 00:58:26.9589451 +0800 +08 m = + 1406.914186601

但是,如果我尝试使用loginTime := time.Now().Format(time.RFC3339),并且编译器抱怨这loginTime是一个string,我需要它是time.time类型.

我可以知道如何处理吗?

很抱歉提出新手问题,Golang和Postgres都是新手.:)

postgresql go

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

如何在 Typescript(Angular Material)中实现回调函数?

我正在使用Angular Material Dialog组件,我想传递一个可选的回调函数,并在用户单击OK button. 我可以知道如何实施吗?

askUser(customData: any) {
    openDialog() {
        const dialogRef = this.dialog.open(AskDialog, {
            data: customData
        });

        dialogRef.afterClosed().subscribe(isOK=> {
            if (isOK && customData.hasOwnProperty('callback')) {
                // ??? how to execute the "customData.callback"
            }
        });
    }
}
Run Code Online (Sandbox Code Playgroud)

我希望我可以这样使用askUser()

function freeGift(gift: string) { /* ... */ }
function contactPolice(phone: number, email: string) { /* ... */ }

askUser({ // callback
    displayText: 'Are you a superman?',
    callback: freeGift('blue shirt')
});

askUser({ // different callback with …
Run Code Online (Sandbox Code Playgroud)

angular-material angular

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