Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 如何使用离子云与离子2,角度2_Angular_Ionic Framework_Ionic2 - Fatal编程技术网

Angular 如何使用离子云与离子2,角度2

Angular 如何使用离子云与离子2,角度2,angular,ionic-framework,ionic2,Angular,Ionic Framework,Ionic2,文件很不清楚。我想知道我应该把代码放在哪里: this.deploy.check().then((snapshotAvailable: boolean) => { this.deploy.download().then(() => { return this.deploy.extract().then( () => { this.deploy.load(); console.log('Extract Succesfu

文件很不清楚。我想知道我应该把代码放在哪里:

 this.deploy.check().then((snapshotAvailable: boolean) => {
    this.deploy.download().then(() => {
        return this.deploy.extract().then( () => {
         this.deploy.load();
         console.log('Extract Succesful');
     };
  });
 });
所以我想要像离子1上的旧行为一样。我可以将代码放在app.ts中,它会监视所有内容(所有页面和所有提供者),检测是否有任何更改,并在客户端设备上进行自动更新。但是医生说我需要在每个页面中注入来自“@ionic/cloud angular”的import{Deploy}?这真让我困惑。我怎么能把一个代码放在一个地方,监视一切。有点像离子1一样,设定它然后忘记它


请帮忙

如果您想在整个应用程序中使用某些内容,通常需要将其添加到
app.ts
files构造函数中


看看这个库,它有一个关于如何在
app.ts
file

中使用它的代码示例。如果您想在整个应用程序中使用某些内容,通常需要将其添加到
app.ts
files构造函数中

看看这个库,它有一个关于如何在
app.ts
文件中使用它的代码示例

浏览本视频教程。这对初学者有好处

完整的文档将在此链接中提供

浏览本视频教程。这对初学者有好处


完整的文档将在此链接中提供

之后,您需要在app.component.ts中添加代码

platform.ready().then(() => {
  ...
  this.watchDeploy();
}
然后,您可以添加以下功能:

watchDeploy(){
// check for update once then with a delay
  this.checkNewVersion().then(()=> {
  setTimeout(()=>this.watchDeploy(), 20 * 1000);
})

checkNewVersion():Promise<any> {
 return new Promise<any>((resolve, reject)=> {
  return this.deploy.check().then((snapshotAvailable: boolean) => {
   if (snapshotAvailable) {
    return this.deploy.download().then(() => {
      return this.deploy.extract().then( () => {
       this.deploy.load();
       console.log('Extract Succesful');
       resolve();
      };
    });
   } else {
       resolve();
   }
  })
 })
}
watchDeploy(){
//检查更新一次,然后延迟
this.checkNewVersion()。然后(()=>{
setTimeout(()=>this.watchDeploy(),20*1000);
})
checkNewVersion():承诺{
返回新承诺((解决、拒绝)=>{
返回此.deploy.check()。然后((snapshotAvailable:boolean)=>{
如果可用(快照可用){
返回此.deploy.download()。然后(()=>{
返回此.deploy.extract()。然后(()=>{
this.deploy.load();
console.log('Extract successful');
解决();
};
});
}否则{
解决();
}
})
})
}
您只需要在使用它的页面中注入“import{Deploy}from'@ionic/cloud angular'”。这里它将仅位于app.component.ts中。
最佳做法是为此创建一个新服务。

之后需要在app.component.ts中添加代码

platform.ready().then(() => {
  ...
  this.watchDeploy();
}
然后,您可以添加以下功能:

watchDeploy(){
// check for update once then with a delay
  this.checkNewVersion().then(()=> {
  setTimeout(()=>this.watchDeploy(), 20 * 1000);
})

checkNewVersion():Promise<any> {
 return new Promise<any>((resolve, reject)=> {
  return this.deploy.check().then((snapshotAvailable: boolean) => {
   if (snapshotAvailable) {
    return this.deploy.download().then(() => {
      return this.deploy.extract().then( () => {
       this.deploy.load();
       console.log('Extract Succesful');
       resolve();
      };
    });
   } else {
       resolve();
   }
  })
 })
}
watchDeploy(){
//检查更新一次,然后延迟
this.checkNewVersion()。然后(()=>{
setTimeout(()=>this.watchDeploy(),20*1000);
})
checkNewVersion():承诺{
返回新承诺((解决、拒绝)=>{
返回此.deploy.check()。然后((snapshotAvailable:boolean)=>{
如果可用(快照可用){
返回此.deploy.download()。然后(()=>{
返回此.deploy.extract()。然后(()=>{
this.deploy.load();
console.log('Extract successful');
解决();
};
});
}否则{
解决();
}
})
})
}
您只需要在使用它的页面中注入“import{Deploy}from'@ionic/cloud angular'”。这里它将仅位于app.component.ts中。 最佳做法是为此创建新的服务