我的员工component.ts代码
import {
Component,
OnInit
} from '@angular/core';
import {
Employee
} from './employeemodel';
import {
NgModule
} from '@angular/core';
import {
EmployeeServiceService
} from '../employee-service.service';
import {
ToastrService
} from 'ngx-toastr';
import {
FormsModule
} from '@angular/forms';
@Component({
selector: 'app-employee',
templateUrl: './employee.component.html',
styleUrls: ['./employee.component.css'],
providers: [EmployeeServiceService]
}) export class EmployeeComponent implements
OnInit {
employee: Employee;emp: any = {}
constructor(private _EmployeeService: EmployeeServiceService, private toastr: ToastrService) {}
ngOnInit() {
var id = parseInt(( <
HTMLInputElement > document.getElementById("txt")).value);
this._EmployeeService.getList()
}
auth(id: number) {
this._EmployeeService.getDetails(id)
.subscribe(employee => employee);
if (id == this.employee.ID) {
this.toastr.success("Login Successful")
}
}
}
我的employeecomponent.html
<div style="text-align:center">
<h2 class="jumbotron bg-secondary text-white">Employee Login</h2>
</div>
<div class="container">
<form name="Emp">
<div class="row">
<div class="col-md-6">
<input id="txt" type="text" name="display" placeholder="EnterPin">
</div>
</div>
</form>
<br>
<button id="btn1" (click)="auth('value');">OK</button>
<button id="btn2" (click)="value=''">CLEAR</button>
<br>
<br>
<div *ngFor="let empl of employee">
{{empl.ID}}
</div>
<div id="1">
<input type="Button" value="7" onclick="Emp.display.value+='7'">
<input type="Button" value="8" onclick="Emp.display.value+='8'">
<input type="Button" value="9" onclick="Emp.display.value+='9'">
<br>
<input type="Button" value="4" onclick="Emp.display.value+='4'">
<input type="Button" value="5" onclick="Emp.display.value+='5'">
<input type="Button" value="6" onclick="Emp.display.value+='6'">
<br>
<input type="Button" value="1" onclick="Emp.display.value+='1'">
<input type="Button" value="2" onclick="Emp.display.value+='2'">
<input type="Button" value="3" onclick="Emp.display.value+='3'">
<br>
<input type="Button" value="0" onclick="Emp.display.value+='0'">
</div>
完成错误EmployeeComponent.html:13 ERROR TypeError:无法读取 财产&#39; ID&#39;在EmployeeComponent.auth中未定义 (employee.component.ts:34)在handleEvent上的Object.eval [as handleEvent](EmployeeComponent.html:13)(core.js:13540) at callWithDebugContext(core.js:15049)at dispatchEvent的Object.debugHandleEvent [as handleEvent](core.js:14636) (core.js:9955)at eval(core.js:10580)at HTMLButtonElement.eval(platform-browser.js:2628)at ZoneDelegate.invokeTask (zone.js:421)在Object.onInvokeTask(core.js:4724)任何建议,我创建了一个角度服务EmployeeServiceService 其中有json数据。我试图让用户输入并验证服务中的Json数据,但我保留 得到错误,不知道接下来该做什么,我是棱角分明的新人,如果这个问题很愚蠢,请道歉
任何建议,我都创建了一个带有json数据的角度服务EmployeeServiceService。我正在尝试获取用户输入并验证来自服务的Json数据,但我不断收到错误,不确定接下来该做什么,我是棱角分明的新人,如果这个问题很愚蠢,请道歉