处理路径时出错:断言失败:必须使用Ember.set()来设置属性

时间:2016-05-18 14:42:06

标签: ember.js

也许我使用它是错误的方式,但我一直收到此错误:“处理路由时出错:注册断言失败:您必须使用Ember.set()来设置errorMessageEmail属性”。这是我的代码:

import Ember from 'ember';

export default Ember.Route.extend({
    resetController: function(controller, isExiting, transition) {
        if (isExiting) {
            controller.set('errorMessageEmail', false);
            controller.set('errorMessagePassword', false);
            controller.set('errorMessageWrong', false);
        }
},

因此,每当我在屏幕上收到错误消息,清理它们然后尝试更改路径时,我会收到此错误,我无法执行任何操作,一切都会被冻结。但我需要清除错误消息。

import Ember from 'ember';
import { translationMacro as t } from "ember-i18n";
import Cookies from 'ember-cli-js-cookie';

export default Ember.Controller.extend({
hasErrorEmail : Ember.computed.empty('identification'),
hasErrorPassword : Ember.computed.empty('password'),
isDisabled: Ember.computed.and('hasErrorEmail','hasErrorPassword'),
errorMessage:Ember.observer('isDisabled',function(){
    if(this.get('isDisabled')){
        this.set('errorMessageWrong', false);
    }else{
        this.set('errorMessageWrong', true);
    }
}),
i18n: Ember.inject.service(),
session: Ember.inject.service(),
isShowingModal:false,
init: function () {
    this._super();
    if(Cookies.get('checked'))
    {
        this.set('identification',Cookies.get('username'));
        this.set('chekRememberMe',true);
    }
},

watchChecked: function(){
    if(Cookies.get('checked')){
        Cookies.remove('username');
        Cookies.remove('checked');
        this.set('identification','');            
    }  
}.observes('chekRememberMe'),

actions: {
    authenticate: function() {

        var credentials = this.getProperties('identification', 'password');
        var emptyEmail=t("login.empty.username");
        var emptyPassword = t("login.empty.password");
        var wrongPassword=t("login.wrong.password");
        var isEmpty=false;
        if(this.get('hasErrorEmail')){
            this.set('errorMessageEmail', emptyEmail);
            isEmpty=true;
        }
        if(this.get('hasErrorPassword')){
            this.set('errorMessagePassword', emptyPassword);
            isEmpty=true;
        }
        if(!isEmpty){
            this.toggleProperty('isShowingModal');
            this.get('session').authenticate('authenticator:custom', credentials).then(() =>{
                if(this.get('chekRememberMe')){
                    if(!Cookies.get('checked')){                    
                        Cookies.set('username',this.get('identification'),{expires: 31,path:''});
                        Cookies.set('checked',true,{expires: 31,path:''});
                    }
                }
                this.transitionToRoute('home-page');
                this.toggleProperty('isShowingModal');
            }).catch((message) => {
                    this.toggleProperty('isShowingModal');
                    this.set('errorMessageWrong', wrongPassword);
                });
        }else{
            this.set('errorMessageWrong', false);
        }     
    },   
},

});

0 个答案:

没有答案