如何动态传递消息属性以警告控制器subTitle属性?

时间:2017-09-30 08:30:06

标签: angular ionic-framework ionic2

.TS

"no permission"

service.ts

//imported everything


@Component({
    selector: 'anything',
    templateUrl: '.html',

})

export class anything{

public x: number;
let message : string;


    constructor(public nav: NavController, public authData: AuthData,public service: Service) { }


   async doSomething() {

       try {

       await this.authData.Something(this.x); 

}
catch(error){
this.message = 'Sorry, sme error occured'

this.service.showAlert();

}            
    }

当调用doSomething()时假设 .ts 类,并且它抛出catch块中捕获的异常,catch块触发警报Controller的showAlert()函数,

问题:如何在showAlert()中动态放置subTitle的值,以便我可以根据所调用的函数发送消息?

注意:请忽略语法错误以及拼写错误和导入。

1 个答案:

答案 0 :(得分:1)

<强> 1。您需要将参数传递给您调用函数

.setsockopt( ZMQ_LINGER,     0 )         # always, indeed ALWAYS
.setsockopt( ZMQ_SNDBUF,    .. )         # always, additional O/S + kernel rules apply ( read more about proper sizing )
.setsockopt( ZMQ_SNDHWM,    .. )         # always, problem-specific data-engineered sizing
.setsockopt( ZMQ_TOS,       .. )         # always, indeed ALWAYS for critical systems
.setsockopt( ZMQ_IMMEDIATE, .. )         # prevents "loosing" messages pumped into incomplete connections

<强> 2。您还需要让服务中的方法知道您正在传递这样的参数。

@Component({
    selector: 'anything',
    templateUrl: '.html',

})

export class anything{

public x: number;
let message : string;


constructor(public nav: NavController, public authData: AuthData,public service: Service) { }


async doSomething() {
       try { 
       await this.authData.Something(this.x);  
         }

catch(error){
this.message = 'Sorry, sme error occured'
//Add message as args to the calling method
this.service.showAlert(this.message); 

 }            
}