簡體   English   中英

綁定在角流星組件上

[英]Binding on angular-meteor components

當我嘗試按照教程進行操作時,在using-and-creating-angularjs-pipes頁面中,this.helpers無法正常工作,因為它僅在綁定發生之前運行。

我不知道這是本教程中的錯誤還是本教程編寫后發生了更改。

當我嘗試在this.helpers函數中執行console.info(binding property)時,結果是不確定的。 當我在$ onInit中執行相同的console.info時,它正在工作。

我該如何運作?

該代碼基於教程https://angular-meteor.com/tutorials/socially/angular1/using-and-creating-angularjs-pipes中的代碼

class PartyCreator{
    constructor($scope){
        'ngInject';
        $scope.viewModel(this);
        this.subscribe('users');

        this.helpers({
            creator: ()=> {
                console.info(this.party) //returns undefined
                if(!this.party){
                    return '';
                }
                const owner = this.party.owner;
                if(Meteor.userId() !== null && owner === Meteor.userId()) {
                    return 'me';
                }

                return Meteor.users.findOne(owner) || 'nobody';
            }
        })
    }


    $onInit(){
        console.info(this.party) //returns valid party object
    }
}

幫助程序會運行多次,基本上是每次數據更改或啟用訂閱時都會運行。 您的代碼應允許不返回任何數據(通常是第一次)。

已經存在處理這種情況的代碼:

       if(!this.party){
            return '';
        }

當它再次運行時,通常會給您您所期望的

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM