我想制作一个包含重复元素的数组.例如:
var myArray = ["one", "two", "five"];
Run Code Online (Sandbox Code Playgroud)
当我循环遍历for循环时:
for(var i = 0; i < myArray.length; i++){
myArray.push(myArray[i]);
}
Run Code Online (Sandbox Code Playgroud)
我的浏览器崩溃了!我没有得到任何有意义的错误.有人可以解释为什么会这样吗?
我尝试对我的输入字段进行验证。
这是我使用的一段代码:
部门组成
import {
FORM_DIRECTIVES,
FormBuilder,
ControlGroup,
Validators ,
AbstractControl
} from 'angular2/common';
@Component({
selector: 'my-departments',
providers: [HTTP_PROVIDERS, DepartmentService],
directives: [FORM_DIRECTIVES, Alert],
styleUrls: ['app/department.component.css'],
templateUrl: 'app/department.component.html',
pipes:[SearchPipe]
})
export class DepartmentComponent implements OnInit {
myForm: ControlGroup;
departmentName: AbstractControl;
departmentLocation: AbstractControl;
constructor(private _router: Router, private _departmentService: DepartmentService, fb: FormBuilder) {
this.myForm = fb.group({
'departmentName': ['', Validators.required],
'departmentLocation': ['', Validators.required]
});
this.departmentName= this.myForm.controls['departmentName'];
this.departmentLocation= this.myForm.controls['departmentLocation'];
}
Run Code Online (Sandbox Code Playgroud)
DepartmentComponent模板
<form [ngFormModel]="myForm"
(ngSubmit)="addDepartment(newItem)" [hidden]="!showAddView" align="center">
<div>
<label for="editAbrv">Department name:</label><br>
<input type="text" [(ngModel)]="newItem.departmentName" [ngFormControl]="myForm.controls['departmentName']" > …Run Code Online (Sandbox Code Playgroud) 我有一个看起来像这样的超时功能:
setTimeout(this.logout, 1000);
Run Code Online (Sandbox Code Playgroud)
登录方式:
logout() {
this.auth_token = "";
this.loggedIn = false;
this.emitLogedInStatusChange();
}
isLoggedIn() {
return this.loggedIn;
}
private emitLogedInStatusChange() {
this.LoggedInStatusChangedEmitter.emit({value: this.loggedIn});
}
Run Code Online (Sandbox Code Playgroud)
其中事件发射器告诉主组件其中loggedIn的值在哪里更改.问题是这个..emitLogedInStatusChange(); 我收到错误信息:
this.emitLogedInStatusChange is not a function
Run Code Online (Sandbox Code Playgroud)
我的问题是如何在注销中正确调用此函数,以便setTimeout可以工作?
这就是我所说的:
map((res) => {
if (res.username === username) {
this.auth_token = res.access_token;
this.sessionId = res.SessionID;
this.loggedIn = true;
this.expires = res.expires_in;
setTimeout(this.logout, this.expires*1000);
this.emitLogedInStatusChange();
}
Run Code Online (Sandbox Code Playgroud) angular ×2
javascript ×2
arrays ×1
for-loop ×1
forms ×1
jquery ×1
settimeout ×1
typescript ×1
validation ×1