我想将数据从HTML传递到组件,所以我创建了这样的事件.
<div id="tutor-price" (click)="passCharge(r.value['charge'])"><span id="month">? 8?</span> <span id="price"> {{r.value['charge']}} </span></div>
Run Code Online (Sandbox Code Playgroud)
在组件中,
passCharge(charge){
this.charge = charge;
console.log(this.charge,"give me the number")
}
Run Code Online (Sandbox Code Playgroud)
如果我点击该活动,我看到一切正常.但是我想自动触发这个click事件,因为我希望组件在组件完成加载后立即使用'this.charge'值.
有什么方法可以自动触发(点击)事件吗?
我正在使用ngFor循环8个json对象,我不仅要循环值,还要计算循环值的数量并显示数字.
例如,如果json值为
Content:{
0:"Content1",
1:"Content2",
2:"Content3",
3:"Content4",
4:"Content5",
5:"Content6",
6:"Content7",
7:"Content8"
}
Run Code Online (Sandbox Code Playgroud)
我不仅要显示'内容'的循环值,还要计算它们,以便结果如下所示.
1 <- counting
Content1
2
Content2
3
Content3
4
Content4
5
Content5
6
Content6
7
Content7
8
Content8
Run Code Online (Sandbox Code Playgroud) 我正在尝试为我的选择设置默认值,所以我尝试了
[selected]= "selected_choice == 'one'"
Run Code Online (Sandbox Code Playgroud)
这样的事情
但这没用.
人们说[选择]不再有效,所以我也试过[attr.selected]但是效果不好..
这是我的一个选择标记的完整代码
<select (change)="passValue3()" formControlName="school" class="form-control" required [(ngModel)]="selected_student" class="selectionbox">
<option *ngIf="selected_student == undefined">?? ??</option>
<option *ngFor="let gradetype of gradeTypes" [ngValue]="gradetype" [attr.selected] = "gradetype.gradeType === 'Middle'">{{gradetype.gradeName}}</option>
</select>
Run Code Online (Sandbox Code Playgroud)
如何设置选择的默认选项?
嗨,我正在尝试使用可能的管道拆分 json 字符串?或者我真的不知道该怎么做。
现在我有 json 字符串
"www.youtube.com||djlajdalksd.png||东西"
(这些只是编的)我只想得到 .png 部分。
我怎么能做到这一点?
嗨,由于angular-cli的版本,我正在部署我的应用程序.
我查了一下,我的angular-cli的版本是
@angular/common: 2.4.10
@angular/compiler: 2.4.10
@angular/core: 2.4.10
@angular/forms: 2.4.10
@angular/http: 2.4.10
@angular/platform-browser: 2.4.10
@angular/platform-browser-dynamic: 2.4.10
@angular/router: 3.4.10
@angular/cli: 1.0.1 <-- 1.0.1
@angular/compiler-cli: 2.4.10
Run Code Online (Sandbox Code Playgroud)
我真的需要将版本降级到1.0.0 beta-24版本.
我怎样才能做到这一点?
我的模拟内存数据库中有youtube链接,我想*来自youtube的这些视频.
let videos: any[] =[
{videoURL: "ZOd5LI4-PcM"},
{videoURL: "d6xQTf8M51A"},
{videoURL :"BIfvIdEJb0U"}
];
Run Code Online (Sandbox Code Playgroud)
像这样.
我使用服务连接我的组件与服务器,现在在HTML中,我已经让v视频.在iframe中,我做到了
<iframe src=v.videoURL></iframe>
Run Code Online (Sandbox Code Playgroud)
但由于它是外部来源,他们告诉我使用Domsanitzer,但我被困在这一部分.
我不知道如何清理应该循环的链接.
constructor( private sanitizer: DomSanitizer) {
this.sanitizer.bypassSecurityTrustResourceUrl('')
Run Code Online (Sandbox Code Playgroud)
< - 我不知道在这里添加什么.
嗨,我无法理解ngIf.
目前我有json的对象
Profile:{
0:{name: 'Jen',
intro:'',
gender:'female',
age:'1992'},
1:{name: 'John',
intro:'Hi',
gender:'male',
age:'1988'}
}
Run Code Online (Sandbox Code Playgroud)
第一个对象的介绍是空字符串,当它有空字符串时我想显示'用户尚未写入它'.
我试过像这样使用ngIf但当然这不起作用.我该怎么办?
<div *ngFor="let p of Profile">
<p class="fontstyle2">
{{p.intro}}
</p>
<p class="fontstyle2" *ngIf="p.intro=''">
The user hasn't written it yet
</p>
</div>
Run Code Online (Sandbox Code Playgroud) 我想创建一个可以将年份(1992年)改为年龄(26岁)(韩国时代)的管道
我想我应该加载当前年份(2017年),减去1992年并加上+1
但我不知道如何用管道来实现这一点.
我提前感谢您的帮助.
嗨,我想把我计算的数字四舍五入到千位.
例如,如果我得到545,000,我希望它是550,000
我创造了一个管道
import {Pipe, PipeTransform} from '@angular/core';
@Pipe({name: 'round'})
export class RoundPipe implements PipeTransform {
transform(value: number): number {
return Math.round(value);
}
}
Run Code Online (Sandbox Code Playgroud)
似乎没有用
任何的想法?
angular ×9
ngfor ×2
pipe ×2
angular-cli ×1
binding ×1
data-binding ×1
json ×1
npm ×1
sanitize ×1
select ×1
split ×1
typescript ×1
youtube ×1