Veki Veki - 1 year ago 88
HTML Question

Error in ... caused by: self.parent.parent.context.aktivirajOglas is not a function

I am having problem with ng2 in my project. I keep getting this error:
"Error in app/korisnik_oglasi/moji_oglasi.html:29:27 caused by: self.parent.parent.context.aktivirajOglas is not a function" and I don't know what to do with it.

This is my component:

import { Component,OnInit} from '@angular/core';
import { OglasiService } from '../oglasi/oglasi.service';
import { Router,ActivatedRoute,Params } from '@angular/router';
import { Observable } from 'rxjs/Observable';
import { Oglas } from '../oglasi/oglas';
import 'rxjs/add/operator/switchMap';

templateUrl: 'app/korisnik_oglasi/moji_oglasi.html',
export class KorisnikOglasComponent implements OnInit {
private _korisnik = './app/korisnik/korisnik.json';
errorMessage: string;
id: number;
oglas : Oglas;

private oglasiService: OglasiService,
private route: ActivatedRoute,
private router: Router
) { }

ngOnInit(): void {
/* = this.route.params
.switchMap((params: Params) => { = +params['id']; });*/

.subscribe(data => this.oglas = data,
error => this.errorMessage = <any>error);

public aktivirajOglas(oglas: Oglas):void{
console.log("Oglas aktiviran");

And this is my template:

<section *ngIf ="oglasi" class="pulldown40 row">
<table class="table table-hover">
<th>Naziv oglasa</th>
<th>Datum kreiranja oglasa</th>
<th>Datum aÅžuriranja oglasa</th>
<th>Datum prestanka oglasa</th>
<tr *ngFor="let oglas of oglasi">
<td><a routerLink="/mojiOglasi/{{}}">Uredi</a></td>
<td><a (click)="aktivirajOglas(oglas);">Aktiviraj</a></td>

Problem is in this aktivirajOglas function. It doesn't recognize it.

Does someone knows what to do?

Answer Source

There seems to be a typo oglas vs oglasi

Plunker example

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download