在这里,我想从其HTML模板调用组件的功能。 但它显示错误如下。 请提出任何更改建议以解决错误。
ERROR TypeError: _co.Get_products is not a function
at Object.eval [as handleEvent] (MapsComponent.html:49)
MapsComponent.html:49 ERROR CONTEXT DebugContext_ {view: {…}, nodeIndex: 9, nodeDef: {…}, elDef: {…}, elView: {…}}
maps.component.html
<button (click)="Get_products()">Function</button>
maps.component.ts
import { Component, OnInit } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { NgForm } from '@angular/forms';
import * as Chart from 'chart.js';
import { Router } from '@angular/router';
import {
AgmCoreModule
} from '@agm/core';
//import { google } from 'googlemaps';
import { MapsAPILoader } from '@agm/core';
import { HttpClient } from '@angular/common/http';
declare const google: any;
interface Marker {
lat: number;
lng: number;
label?: string;
draggable?: boolean;
}
@Component({
selector: 'app-maps',
templateUrl: './maps.component.html',
styleUrls: ['./maps.component.css']
})
export class MapsComponent implements OnInit {
constructor() { }
private products = [];
ngOnInit() {
.......
function Get_products(){
console.log('Hello');
}
......
}
}
答案 0 :(得分:0)
您应将Get_products
之外的ngOnInit
定义为MapsComponent
类的方法。
private products = [];
constructor() { }
ngOnInit() {
.......
}
Get_products(){
console.log('Hello');
}