小编ibe*_*oun的帖子

多个组件绑定相同的反应形式控制更新问题

在某些情况下,我们可能需要将多个表单组件绑定到同一个表单控件.我对处理这种情况的角度方式感到困惑:

更改其中一个组件值时,将更改表单值,但不会更改其他组件值.

我在这种情况下做的解决方法是使用表单值修补from,这很难看:

this.form.patchValue(this.form.value);
Run Code Online (Sandbox Code Playgroud)

这是针对我的问题的stackblitz演示,我为输入更改添加了解决方法而不是选择以便更好地理解.

是否有一种优雅的方式来处理角度反应形式的情况?

angular angular-reactive-forms

9
推荐指数
2
解决办法
3469
查看次数

Angular 6 - run方法每10秒服务一次

我有这个服务使用HttpClient来获取一些数据:

checkData() {
    return this.http.get('my url');
}
Run Code Online (Sandbox Code Playgroud)

我在脚注组件上调用它并显示结果:

ngOnInit() {
    this.myservice.checkdata().subscribe( result => { this.statustext = result } );
}
Run Code Online (Sandbox Code Playgroud)

这有效,但我需要每10秒运行一次这样的方法,因此它是最新的.

我怎样才能做到这一点?

rxjs typescript angular angular6

9
推荐指数
2
解决办法
2万
查看次数

Angular 6路由参数

目前我正在为我的应用使用此路由设置:

{
  path: ':group',
  component: ArticleListComponent,
  children: [{
      path: ':subgroup',
      component: ArticleListComponent,
      children: [{
          path: ':chapter',
          component: ArticleListComponent,
          children: [{
              path: ':section',
              component: ArticleListComponent,
              children: [
              ]
            }
          ]
        }
      ]
    }
  ]
},
Run Code Online (Sandbox Code Playgroud)

我使用相同的组件来列出文章,因为模板和代码不会改变,但我想使用url来过滤这些文章.应用程序应该使用路由参数而不是获取参数.有了这些参数,我想调用一个API来获取属于这个url的文章:/ group1/subgroup1/chapter1/section1.

问题是我只使用以下代码获取这些参数:

const params = this.route.snapshot.params;
// {group: "group1"}

const params = this.route.parent.snapshot.params;
// {}

const params = this.route.firstChild.snapshot.params;
// {group: "group1", subgroup: "subgroup1"}
Run Code Online (Sandbox Code Playgroud)

我怎么能一次得到所有这些参数?

parameters routing angular

5
推荐指数
0
解决办法
2896
查看次数

如何让*ngFor循环执行前n-1次,不希望显示最后一个索引的数据?

HTML:

<div *ngIf="userdata; else blank;">                         
 <table>
  <thead>
   <tr>
    <th>Id</th>
    <th>Name</th>
    <th>Email</th>
    <th>Address</th>
    <th>Role</th>
    <th>Gender</th>
    <th>Actions</th>
   </tr>
  </thead>
  <tbody>
   <tr *ngFor="let data of userdata">                                          
    <td>{{data.Id}}</td>
    <td>{{data.Name}}</td>
    <td>{{data.Email}}</td>
    <td>{{data.Address}}</td>
    <td>{{data.Role}}</td>
    <td>{{data.Gender}}</td>
    <td>
     <button type="button" (click)="setUser(data)" class="btn btn-default btn-sm edit">
      <span class="glyphicon glyphicon-edit"/> Edit</button>                                              
     <button type="button" id="close" style="height: 30px;"
      (click)="deleteUser(data.Id)" class="btn btn-default btn-sm close" aria-label="Close">
      <span aria-hidden="true">&times;</span>
     </button>
    </td>                                           
   </tr>  
  </tbody>
 </table>
</div>
<ng-template #blank>No Records found...</ng-template>
Run Code Online (Sandbox Code Playgroud)

这是我在userdata数组中得到的:

[{
    "Id": "1",
    "Name": "sdfd",
    "Email": "fdg",
    "Address": "dfg",
    "Role": "Admin",
    "Gender": "male"
}, { …
Run Code Online (Sandbox Code Playgroud)

typescript angular angular6

4
推荐指数
1
解决办法
154
查看次数