我使用 jQuery dataTable 在列表视图上显示数据。我尝试使用以下方式将数据绑定到 dataTable 。
在 users.component.ts 上
getUsers() {
this.UserService.getUsersList()
.subscribe(
success => {
this.userList = success;
$("#userTable").find('tbody').empty();
var dataClaims = this.userList;
for (let i = 0; i < dataClaims.length; i++) {
$('#userTable').dataTable().fnAddData([
(i + 1),
dataClaims[i].name,
dataClaims[i].email,
dataClaims[i].contact_number,
dataClaims[i].address,
'<a [routerLink]="[' +"'"+"../../user/update" +"'" +']"' + ' class="fa fa-1x fa-pencil-square-o"></a>',
]);
}
}
);
}
Run Code Online (Sandbox Code Playgroud)
上述功能正常工作,数据表工作没有问题。
但[routerLink]没有转换为 html。在输出中,它显示如下:
<a [routerlink]="['../../user/update']" class="fa fa-1x fa-pencil-square-o"></a>
Run Code Online (Sandbox Code Playgroud)
但它应该转换为以下方式,
<a _ngcontent-c0="" ng-reflect-router-link="user/update" href="/user/update" class="fa fa-1x fa-pencil-square-o"></a>
Run Code Online (Sandbox Code Playgroud)
[routerlink]有人可以解释一下在从 .ts 文件渲染 …
我想将类直接添加到 Angular 5 中的选择器中。如下所示:
<myapp-selector class="myclass"></myapp-selector>
Run Code Online (Sandbox Code Playgroud)
我已经搜索了一段时间,找到了一些解决方案,例如使用hostof @Component。但我无法找到具体问题的明确答案。
它安全吗?这被认为是一种不好的做法吗?
我的子组件如下所示:
...
@Component({
selector: '[child-component]'
templateUrl: './child.template.html'
})
...
Run Code Online (Sandbox Code Playgroud)
我的父模板如下:
<span child-component [someInput]="123"></span>
Run Code Online (Sandbox Code Playgroud)
现在我想渲染子组件的内容,而<span>周围没有容器。我不想在父组件的模板中出现任何容器,只需要子组件模板的内容。
我已经尝试过其他一些标签了。
<ng-content>(根本没有渲染任何东西)<ng-template>(嵌入模板上的组件:)<ng-container>(无法在“节点”上执行“appendChild”)提前致谢!
dom angular2-directives angular2-template angular2-ngcontent angular
通过阅读一些 Angular 资源(见下文),调用模板中的方法可能会导致性能问题。例如
<div>{{getDisplayName()}}</div>
Run Code Online (Sandbox Code Playgroud)
然而,相当多的 Angular Material 库示例调用模板中的方法。
树
https://material.angular.io/components/tree/examples
<mat-icon class="mat-icon-rtl-mirror">
{{treeControl.isExpanded(node) ? 'expand_more' : 'chevron_right'}}
</mat-icon>
Run Code Online (Sandbox Code Playgroud)
带有选择的表
https://material.angular.io/components/table/examples
<td mat-cell *matCellDef="let row">
<mat-checkbox (click)="$event.stopPropagation()"
(change)="$event ? selection.toggle(row) : null"
[checked]="selection.isSelected(row)"
[aria-label]="checkboxLabel(row)">
</mat-checkbox>
</td>
Run Code Online (Sandbox Code Playgroud)
这些方法确实从 Set 中返回一个值。例如 https://github.com/angular/components/blob/4d4ee182de3f306c5fcf49853ef6ac71c4000eea/src/cdk/collections/selection.ts
isSelected(value: T): boolean {
return this._selection.has(value);
}
Run Code Online (Sandbox Code Playgroud)
这些方法会像*普通方法一样导致性能问题吗?或者我缺少什么?
资源
我的目的是使用枚举来读取数组的属性。这段代码给我错误:
<ng-container *ngFor="let elem of list">
<div class="ui-g-12 ui-sm-12 ui-md-12 ui-lg-12 ui-xl-12">
<div class="ui-g-12 ui-sm-12 ui-md-12 ui-lg-3 ui-xl-3">
<input type="text" pInputText value="{{elem[StudentEnum.name] }}" name="student_name" />
</div>
</ng-container>
Run Code Online (Sandbox Code Playgroud)
StudentEnum是一个枚举类,但是如果我放入模板中它就不起作用。在模板中使用枚举读取数组属性和值的正确方法是什么?
{{ elem[StudentEnum.name] }}
Run Code Online (Sandbox Code Playgroud) 为什么templateUrl不工作在角度2.当我使用模板它工作.它不工作..我的代码
http://plnkr.co/edit/WI4gK2vbaj4OUX5ImJor?p=preview
import {Component,View} from 'angular2/core';
@Component({
selector: 'my-app',
// template: '<div (click)="onclck()">hello</div>'
})
@View({
templateUrl: 'home/home.html'
});
export class AppComponent {
onclck(){
alert('--')
}
}
Run Code Online (Sandbox Code Playgroud) 我创建了一个组件,意在成为一个开关.您可以像使用复选框一样使用它.这是一个精简版.
我-switch.component.ts:
import {Component, Input, Output, EventEmitter} from '@angular/core';
@Component({
selector: 'my-switch',
template: `<a (click)='toggle()'>
<span *ngIf='value'>{{onText}}</span>
<span *ngIf='!value'>{{offText}}</span>
</a>`
})
export class MySwitchComponent {
@Input() onText: string = 'On';
@Input() offText: string = 'Off';
@Input() value: boolean;
@Output() change = new EventEmitter <boolean> ();
position: string;
toggle() {
this.value = !this.value;
this.change.emit(this.value);
}
}
Run Code Online (Sandbox Code Playgroud)
我的计划是这样使用它:
家长component.ts
import {Component} from '@angular/core';
import {MySwitchComponent} from 'my-switch.component';
@Component({
selector: 'my-sites',
directives: [MySwitchComponent]
template: `<table>
<tr *ngFor='let item of items'>
<td>
<my-switch
[(value)]='item.options.option1' …Run Code Online (Sandbox Code Playgroud) 我尝试使用ListView组件ngForTemplate进行自定义模板
列表view.component.html
<div class="list-view">
<template ngFor [ngForOf]="items" [ngForTemplate]="template">
</template>
</div>
Run Code Online (Sandbox Code Playgroud)
列表view.component.ts
@Component({
selector: 'm-list-view',
styleUrls: ['./list-view.component.less'],
templateUrl: './list-view.component.html'
})
export class ListViewComponent {
@Input() items: any[] = [];
@ContentChild(TemplateRef)
template: any;
}
Run Code Online (Sandbox Code Playgroud)
当我像这样使用它时:
<m-list-view [items]="categories">
<template let-item="$implicit">
**some HTML markup**
</template>
</m-list-view>
Run Code Online (Sandbox Code Playgroud)
结果是:
<m-list-view>
<div class="list-view">
**some HTML markup**
**some HTML markup**
**some HTML markup**
...
</div>
</m-list-view>
Run Code Online (Sandbox Code Playgroud)
但我需要这个:
<m-list-view>
<div class="list-view">
<div class="list-view-item">**some HTML markup**</div>
<div class="list-view-item">**some HTML markup**</div>
<div class="list-view-item">**some HTML markup**</div>
...
</div>
</m-list-view>
Run Code Online (Sandbox Code Playgroud)
我该怎么做才能在div.list-view-item中包装每个列表视图项模板?
我有这个从列表动态创建的输入column,现在我需要在某些方法发生时获取所有输入值(想象getAllValues())
<div *ngFor="let cell of column; let i = index;">
<!-- Material design input-->
<md-input type="{{cell.type}}"
value="{{getInputValue(cell)}}"
[placeholder]="cell.label">
</md-input>
</div>
Run Code Online (Sandbox Code Playgroud)
获取所有生成输入的值的angular2方法是什么?
angular-material angular2-directives angular2-template angular2-material angular
我开发了一个Angular 2应用程序,我试图在其中应用CSS类ngClass.我已将类名存储在变量中className并尝试使用以下代码来应用:
第一种方式
[ngClass]={'{{className}}': expression}
Run Code Online (Sandbox Code Playgroud)第二种方式
[ngClass]= {className: expression}
Run Code Online (Sandbox Code Playgroud)但他们都没有奏效.