我是Angular 2的新手.
我有一个列表并迭代它并显示为单选按钮,如下所示.现在我想在条件为TRUE时设置check属性.如何在Angular 2中做到这一点?
<table *ngIf="optionList">
<tr *ngFor="let op of optionList; let i = index">
<td>
<input type="radio" name="optradio" *ngIf=" (CONDITION HERE) ? 'checked' : 'non' ">
<label>{{op.option_text}} </label>
<td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud) 我是Typescript和Angular 2的新手.我试图在网上寻找答案,但似乎它们对我不起作用.
假设我有一个app.component,如下所示:
export class AppComponent implements OnInit {
constructor(public _testService: TestService) { }
listForCart = this._testService.getListForCart();
cartCount = this.listForCart.length;
cartPayableAmount = 0;
ngOnInit() {
this.computeTotal();
}
TestingFunction(){
console.log("Got here");
}
}
Run Code Online (Sandbox Code Playgroud)
现在我想访问其他类中app.component中的TestingFunction,如下所示:
export class BuyTestComponent {
constructor(private _testService: TestService) {
}
public pageTitle: string = "ALL PRACTICE TEST SERIES";
TestHere() {
// should call TestingFunction() here.....
}
}
Run Code Online (Sandbox Code Playgroud)
怎么做?请帮忙
我想在我的应用程序中使用Angular的DatePickerModule.所以我按如下方式安装了软件包:npm install ng2-datepicker-bootstrap --save
安装成功.现在,我在AppModule中导入了DatePickerModule模块,如下所示:
import { DatePickerModule } from 'ng2-datepicker-bootstrap';
@NgModule({
declarations: [
other Components......,
DatePickerModule
],
imports: [
........
],
providers: [Service, DatePickerModule],
bootstrap: [AppComponent]
})
export class AppModule { }
Run Code Online (Sandbox Code Playgroud)
然后在我的info.component.html中使用以下代码.
<datepicker [(ngModel)]="model.firstDate" [viewFormat]="'DD/MM/YYYY'" [modelFormat]="'YYYY-MM-DD'" [id]="'firstDate'" [label]="'To'"></datepicker>
Run Code Online (Sandbox Code Playgroud)
但是当我运行项目时,我收到了这个错误: 错误:模块'AppModule'声明的意外模块'DatePickerModule'.请添加@ Pipe/@ Directive/@ Component注释.
顺便说一句,我是Angular2的新手.
我是Python的新手
我有以下代码:
在我的内部有另一个for循环然后第二个for循环调用一个函数,它执行另一个for循环.现在我希望第二个for循环等到第三个循环完成它的工作.怎么做?
谢谢
def GetArea(img):
os.chdir("C:\RJC Files\Thesis\Biometrics Thesis\Raw Data\Pics\PickedImages\\" + str(x) + "\\Process")
for file2 in glob.glob("*.png"):
# DO SOMETHING
# TAKE SOMETIME TO FINISH HERE.
-----------------------------------------------------------
for x in range(1, 2):
os.chdir("C:\RJC Files\Thesis\Biometrics Thesis\Raw Data\Pics\PickedImages\\" + str(x) + "\\Area")
for file in glob.glob("*.png"):
img = cv2.imread(file, 0)
GetArea(img)
Run Code Online (Sandbox Code Playgroud) 顺便说一下,我是Typescript和Angular2的新手.
我有一个返回类型为PracticeTestList的对象的服务.服务和对象的声明如下所示.
现在,我有一个读取对象的自定义管道,如下所示.
自定义管道类确实收到了对象,但在for循环中,对象被读取为单行字符串而不是对象.这是为什么?
如何在Typescript中将对象作为对象读取?
谢谢
服务
getMyPracticeTest(uid: string){
return this._http.get('http://localhost:49753/RestServiceImpl.svc/getMyPracticeTest/' + uid)
.map(data => {
data.json();
// the console.log(...) line prevents your code from working
// either remove it or add the line below (return ...)
console.log("getMyPracticeTest >>>>>>> ", <PracticeTestList[]>data.json());
return <PracticeTestList[]>data.json();
});
}
Run Code Online (Sandbox Code Playgroud)
对象声明
import { Injectable } from '@angular/core';
@Injectable()
export interface PracticeTestList {
Purchase_ID: number;
User_FK: number;
name: string;
price: number;
resteurant: string;
credit_card_number: string;
purchase_date : any;
Test_Status_FK: number; …Run Code Online (Sandbox Code Playgroud) 我试图在Angular中向浏览器显示一个简单的数据,但是我想在从服务中检索所有数据后显示数据.
怎么做?
目前,即使没有完成获取数据,页面也会显示.
这是示例代码
In test.component.ts file
ngOnInit() {
this._service.getQuestions().subscribe(data => { this.questionCollection = data });
}
Run Code Online (Sandbox Code Playgroud)
在我的服务中
getQuestions() {
return this._http.get('assets/questions.json')
.map(res => res.json())
.catch(this.handleError);
}
Run Code Online (Sandbox Code Playgroud)
.html文件
<div> Other text here...... </div>
<div *ngFor="let col of questionCollection">
<button type="button" class="btn btn-default">{{col.Text}}</button>
</div>
Run Code Online (Sandbox Code Playgroud)