2017-06-10 4 views
0

私はコンボボックスに選択した行から値を設定しようとしているんだけど、これだけは私のページの私の一部である入力セットコンボボックスの値部材角4

がロード

` <form class="form-horizontal form-label-left parsleyjs" method="post" data-parsley-priority-enabled="false" novalidate="novalidate"> 
     <fieldset> 
     <div class="form-group row"> 
      <label class="form-control-label labelName" for="basic-change"> 
      Name 
      </label> 
      <div class="inputName"> 
      <input #newRole type="text" id="basic-change" name="basic-change" class="form-control" data-parsley-minlength="4" data-parsley-trigger="change" 
       maxlength="50" value="{{role.name}}" required="required"> 
      </div> 
     </div> 
     <div class="inputName"> 
      <select #newEnv class="form-control" required="required"> 
        <option value="b">Back Office</option> 
        <option value="c">Casino</option> 
        <option value="s">Store</option> 
       </select> 
      </div> 
      div class="form-group row"> 
      <label class="form-control-label labelName" for="basic-change"> 
      Description 
      </label> 
      <div class="inputName"> 
      <input #newDesc type="text" id="basic-change" name="basic-change" class="form-control" data-parsley-minlength="4" data-parsley-trigger="change" 
       value="{{role.description}}" required="required"> 
      </div> 
      </fieldset> 
     </form> 

これは私のコンポーネントである

export class RolesReplaceComponent implements OnInit { 
@ViewChild('modal') public modal: ModalDirective; 
mensaje: string; 
error: boolean; 
role; 
private isLoading = false; 
constructor(
private route: ActivatedRoute, 
private router: Router, 
private svrRole: RoleService, 
private http: Http, 
private trans: TranslateService,) { 
this.error = false; 
} 

ngOnInit(): void { 
jQuery('.parsleyjs').parsley(); 
this.isLoading = true; 
this.svrRole = new RoleService(this.http); 
this.route.params 
    .subscribe(
    param => { 
    this.svrRole.getById(param['id'], null) 
     .subscribe(
     resp => { 
     console.log(resp); 
     this.role = resp.data.data; 
     console.log(this.role); 
     this.isLoading = false; 
     console.log('Que sucedio?'); 
     }, 
     error => console.log("Error on edit-roles-services ", error)); 
    } 
    ); 
} 
} 

私は<select>

012は動作しません入力をロードするために使用するのと同じ方法を使用する場合

いくつかのアイデアをどのように行うのですか?

+0

'this.role'の中で' select'にマップしたい属性の名前は何ですか? – CodeWarrior

+0

2ウェイデータバインディング[こちら](https://angular.io/docs/ts/latest/guide/template-syntax.html#!#binding-syntax)に目を通してください。 –

答えて

0

まあ、私がこの変数を追加するために持っているコンポーネントに追加するだけで2行だったが、finnally作品、 :

options:any = [{value:'b', name:"Back Office"},{value:'c', name:"Casino"},{value:'s', name:"Store"}];

をし、オプションタグでこれを置き換える:

<option *ngFor="let p of options" [value]="p.value" [selected]="p.value == role.environment">{{p.name}}</option>

関連する問題