导致的错误:self.parent.parent.context.aktivirajOglas不是一个函数

时间:2016-11-27 16:09:54

标签: html angular

我在项目中遇到ng2问题。我一直收到这个错误: “app / korisnik_oglasi / moji_oglasi.html:29:27引起的错误:self.parent.parent.context.aktivirajOglas不是一个函数”,我不知道如何处理它。

这是我的组成部分:

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';

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

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


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

       this.oglasiService.dohvatiOglas(this.id)
        .subscribe(data => this.oglas = data,
        error => this.errorMessage = <any>error);
    }

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

这是我的模板:

  <section *ngIf ="oglasi" class="pulldown40 row">
          <table class="table table-hover">
            <thead>
              <tr>
                <th>#</th>
                <th>Naziv oglasa</th>
                <th>Datum kreiranja oglasa</th>
                <th>Datum ažuriranja oglasa</th>
                <th>Datum prestanka oglasa</th>
                <th>Status</th>
                <th></th>
                <th></th>
              </tr>
            </thead>
            <tbody>
              <tr *ngFor="let oglas of oglasi">
                <td>{{oglas.id}}</td>
                <td>{{oglas.naziv}}</td>
                <td>15.11.2016</td>
                <td>16.11.2016</td>
                <td>21.11.2016</td>
                <td>{{oglas.status_opis}}</td>
                <td><a routerLink="/mojiOglasi/{{oglas.id}}">Uredi</a></td>
                <td><a (click)="aktivirajOglas(oglas);">Aktiviraj</a></td>
              </tr>
            </tbody>
          </table>
  </section>

问题出在这个aktivirajOglas函数中。它不承认它。

有人知道该怎么做吗?

1 个答案:

答案 0 :(得分:2)

似乎有一个拼写错误oglasoglasi

Plunker example