【问题标题】:Ionic / Angular hide or shuffle part of url离子/角度隐藏或洗牌部分网址
【发布时间】:2021-03-28 18:59:21
【问题描述】:

app-routing.module.ts 中有 3 个路径,我在其中传递参数,下面是一个示例。

有什么方法可以直接在 app-routing.module.ts 中隐藏或随机播放部分 url?并得到这样的结果。

http:localhost/edit-channel

http:localhost/edit-channel/jhsdjhySDNsdsdbSMKDHsodyoiwhemnzkdhSDsndmhoicyoiwherM

【问题讨论】:

    标签: angular ionic-framework


    【解决方案1】:

    我选择创建一个不通过 URL 传递数据的对象。

    这样网址就清楚了。

    组件 A 调用组件 B 并将数据发送到对象服务。

    this._EditChannelService.EditChannel(_id, title, description, visibility);
    

    对象服务

    export class EditChannelService {
        private _ID = new BehaviorSubject<any>("");
        private _Title = new BehaviorSubject<any>("");
        private _Description = new BehaviorSubject<any>("");
        private _Visibility = new BehaviorSubject<any>("");
    
        get ID$() {
            return this._ID.asObservable();
        }
    
        get Title$() {
            return this._Title.asObservable();
        }
    
        get Description$() {
            return this._Description.asObservable();
        }
    
        get Visibility$() {
            return this._Visibility.asObservable();
        }
    
        constructor(
            public _Router: Router,
        ) {
        }
    
        EditChannel(id: any, title: any, description: any, visibility: any) {
            this._ID.next(id);
            this._Title.next(title);
            this._Description.next(description);
            this._Visibility.next(visibility);
    
            this._Router.navigate(['edit-channel']);
        }
    }
    

    组件 B 在初始化时获取数据

      ngOnInit() {
        this._EditChannelService.ID$.subscribe(data => {
          this.editChannelForm.get('_id').setValue(data);
        }).unsubscribe;
    
        this._EditChannelService.Title$.subscribe(data => {
          this.editChannelForm.get('title').setValue(data);
        }).unsubscribe;
    
        this._EditChannelService.Description$.subscribe(data => {
          this.editChannelForm.get('description').setValue(data);
        }).unsubscribe;
    
        this._EditChannelService.Visibility$.subscribe(data => {
          this.editChannelForm.get('visibility').setValue(data);
        }).unsubscribe;
      }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-02-17
      • 1970-01-01
      • 2018-03-25
      • 2018-03-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多