输入更改时,角度控制器中的变量过滤不会更新

时间:2018-03-25 13:55:02

标签: angularjs

我的组件中有这个:

  <div *ngFor="let hotel of hotels">
    <div>Photo</div>
    <div>{{ hotel.name }}</div>
    <div><button (click)="changeIsShohToTrue()" type="button" class="btn btn-default btn"><i class="glyphicon glyphicon-align-justify"></i></button></div>

    <div *ngIf="isShow">Additional information</div>
  </div>  

这在服务中:

const template = require('./cart.html');
import GamesService, { Game } from '../../games.service';

export class CartComponent implements ng.IComponentOptions {
    public controller = CartController;
    public template = template;
}

export class CartController implements ng.IComponentController {
    public static $inject = ['GamesService', 'filterFilter'];

    public games: Game[];

    constructor(public gamesService: GamesService, filterFilter: ng.IFilterFilter) {
    this.games = filterFilter(gamesService.getAll(), { inCart: true });
    }

    public addToCart(game: Game) {
        this.gamesService.addToCart(game);
    }

    public removeFromCart(game: Game) {
        this.gamesService.removeFromCart(game);
    }
}

当我将项目添加到购物车时,列表不会更新。如果我不在控制器中使用filterFilter并在模板中将其用作“| filter:{inCart:true}”,则列表会在每次更改时更新。 能告诉我控制器或服务有什么问题吗?

0 个答案:

没有答案