小编k.e*_*rer的帖子

导航到另一个页面后,离子组件未损坏

我目前正在研究项目为Angular 6,Ionic 4 Hybrid的旧代码。所有功能模块正在延迟加载。

问题是,导航到另一页后,我可以在nav工具的“内存”选项卡上看到上一页仍然存在,ngOnDestroy并且尚未真正触发。

为了给您更多细节,我的应用程序路由模块是:

import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { routes } from './app.routes';


 @NgModule({
imports: [RouterModule.forRoot(routes, { enableTracing: false, useHash: false  
 })],
  exports: [RouterModule],
 })
 export class AppRoutingModule { }  
Run Code Online (Sandbox Code Playgroud)

我的路线是:

  export const routes: Routes = [
     { 
       path: '', redirectTo: '/home',
       pathMatch: 'full' 
     },
     { 
     path: 'accounts',
     loadChildren: 
    '../pages/accounts/accounts.page.module#AccountsPageModule',
      canActivate: [AuthGuardService] 
     },
     {
     path: 'administration',
     loadChildren:      
'../pages/administration/administration.page.module#AdministrationPageModule' 
     },
    { 
     path: 'bookings',
     loadChildren: 
     '../pages/bookings/bookings.page.module#BookingsPageModule',
     canActivate: [AuthGuardService],

  }, …
Run Code Online (Sandbox Code Playgroud)

ionic-framework angular

8
推荐指数
4
解决办法
4869
查看次数

如何在 jQuery 中的 $.when().then() 中使用 If 语句

我使用作为 JavaScript 控制器的初始化一个方法来获取参数。根据参数的值,我使用 $.when() 和 then() 方法从 ajax 调用中获取数据。

具体来说,如果传递的参数在 $.when 中为真,我想有 4 个 ajax 调用,否则有 3 个。

$.when(
    $.ajax({
        url: "test.html"
    }).done(function () {
        $(this).addClass("done");
    }),
    $.ajax({
        url: "test2.html"
    }).done(function () {
        $(this).addClass("done");
    }),
    $.ajax({
        url: "test3.html"
    }).done(function () {
        $(this).addClass("done");
    }),
    if (config,EditMode) {
        $.ajax({
            url: "test3.html"
        }).done(function () {
            $(this).addClass("done");
        })
    }
).then(function () {
    if (config,EditMode)
        somemethod();
    else
        someOtherMethod();
}).done(function () {
    //code
});
Run Code Online (Sandbox Code Playgroud)

我尝试了类似上面的方法,但我无法真正使语法起作用。当然,我可以创建一个全局 if else 并复制代码。但我会收到 DRY 原则的投诉:))。

你有什么想法吗?谢谢

javascript jquery

0
推荐指数
1
解决办法
212
查看次数

标签 统计

angular ×1

ionic-framework ×1

javascript ×1

jquery ×1