Refresh select options in angular utilizing two selects

Multi tool use
up vote
1
down vote
favorite
i have this select:
Template:
<div class="select">
<select (change)="getIdTipoVariacao(item.value.tipo)" formControlName="tipo" class="select-text">
<option class="dropdown-item" selected>{{item.value.tipo || 'Tipo da Variação'}}</option>
<option [hidden]="item.value.tipo == tipoVariacao.valor" *ngFor="let tipoVariacao of tiposvariacoes;let j = index"
class="dropdown-item">{{tipoVariacao.valor}}</option>
</select>
<span class="select-highlight"></span>
<span class="select-bar"></span>
</div>
In my component, throught the function getIdTipoVariacao() i catch the id of my "variacao" selected:
getIdTipoVariacao(variacao:string) { // take the id of one "tipo de variação" to send to function get-lista-valor-atributo to get the list of attributs of my "variation":
for(let i=0;i<this.tiposvariacoes.length;i++){
if(this.tiposvariacoes[i].valor == variacao){
this.idTipoVariacao = this.tiposvariacoes[i].id
}
}
this.listaValoresAtributo(this.idTipoVariacao);
}
listaValoresAtributo(id: number){
console.log(id)
this.tipoProdutoService.listaValoresAtributo(id)
.pipe(
take(1)
)
.subscribe((res) => {
console.log(res);
this.listaAtributos = res.data.valores_atributos;
this.loadingfiltro = false;
},
(err: HttpErrorResponse) => {
if (err.status == 401) {
this.authService.Logout();
}
if (err.error.data.erro) {
this.toastrService.showToast(false, 'Ops, temos um problema', err.error.data.erro);
} else {
this.toastrService.showToast(false, 'Ops, temos um problema', 'Entre em contato com o suporte!');
}
})
}
Everythings work well, this function take the id of my variation and send to my backend, that me returns an array (this.listaAtributos), i have to copulate the other select.
In my second select i do one ngfor trying to copulate the options according the answer of my server, but no one data is copulate. If i print a console.log in this.listaAtributos, i see my array with my data that i need to coppulate. How can i do this?
My second select:
<div class="col-md-2">
<div class="select">
<select formControlName="valor" class="select-text">
<option class="dropdown-item" selected>{{item.value.valor || 'Valor'}}</option>
<option *ngFor="let ValorAtributo of listaAtributos;let x = index"
class="dropdown-item">{{ValorAtributo.valor}}</option>
</select>
<span class="select-highlight"></span>
<span class="select-bar"></span>
</div>
</div>
Observables? Someone can teach me?
angular typescript
add a comment |
up vote
1
down vote
favorite
i have this select:
Template:
<div class="select">
<select (change)="getIdTipoVariacao(item.value.tipo)" formControlName="tipo" class="select-text">
<option class="dropdown-item" selected>{{item.value.tipo || 'Tipo da Variação'}}</option>
<option [hidden]="item.value.tipo == tipoVariacao.valor" *ngFor="let tipoVariacao of tiposvariacoes;let j = index"
class="dropdown-item">{{tipoVariacao.valor}}</option>
</select>
<span class="select-highlight"></span>
<span class="select-bar"></span>
</div>
In my component, throught the function getIdTipoVariacao() i catch the id of my "variacao" selected:
getIdTipoVariacao(variacao:string) { // take the id of one "tipo de variação" to send to function get-lista-valor-atributo to get the list of attributs of my "variation":
for(let i=0;i<this.tiposvariacoes.length;i++){
if(this.tiposvariacoes[i].valor == variacao){
this.idTipoVariacao = this.tiposvariacoes[i].id
}
}
this.listaValoresAtributo(this.idTipoVariacao);
}
listaValoresAtributo(id: number){
console.log(id)
this.tipoProdutoService.listaValoresAtributo(id)
.pipe(
take(1)
)
.subscribe((res) => {
console.log(res);
this.listaAtributos = res.data.valores_atributos;
this.loadingfiltro = false;
},
(err: HttpErrorResponse) => {
if (err.status == 401) {
this.authService.Logout();
}
if (err.error.data.erro) {
this.toastrService.showToast(false, 'Ops, temos um problema', err.error.data.erro);
} else {
this.toastrService.showToast(false, 'Ops, temos um problema', 'Entre em contato com o suporte!');
}
})
}
Everythings work well, this function take the id of my variation and send to my backend, that me returns an array (this.listaAtributos), i have to copulate the other select.
In my second select i do one ngfor trying to copulate the options according the answer of my server, but no one data is copulate. If i print a console.log in this.listaAtributos, i see my array with my data that i need to coppulate. How can i do this?
My second select:
<div class="col-md-2">
<div class="select">
<select formControlName="valor" class="select-text">
<option class="dropdown-item" selected>{{item.value.valor || 'Valor'}}</option>
<option *ngFor="let ValorAtributo of listaAtributos;let x = index"
class="dropdown-item">{{ValorAtributo.valor}}</option>
</select>
<span class="select-highlight"></span>
<span class="select-bar"></span>
</div>
</div>
Observables? Someone can teach me?
angular typescript
What do you see in the options ?
– Sunil Singh
Nov 5 at 17:59
my options is empty
– Renato Veronese
Nov 5 at 18:28
Your code is looking fine to me. Are you getting any error in console ?
– Sunil Singh
Nov 5 at 18:50
Can you verify if the listaAtributos is actually a list(array) and not an object
– Sachin Gupta
Nov 5 at 19:17
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
i have this select:
Template:
<div class="select">
<select (change)="getIdTipoVariacao(item.value.tipo)" formControlName="tipo" class="select-text">
<option class="dropdown-item" selected>{{item.value.tipo || 'Tipo da Variação'}}</option>
<option [hidden]="item.value.tipo == tipoVariacao.valor" *ngFor="let tipoVariacao of tiposvariacoes;let j = index"
class="dropdown-item">{{tipoVariacao.valor}}</option>
</select>
<span class="select-highlight"></span>
<span class="select-bar"></span>
</div>
In my component, throught the function getIdTipoVariacao() i catch the id of my "variacao" selected:
getIdTipoVariacao(variacao:string) { // take the id of one "tipo de variação" to send to function get-lista-valor-atributo to get the list of attributs of my "variation":
for(let i=0;i<this.tiposvariacoes.length;i++){
if(this.tiposvariacoes[i].valor == variacao){
this.idTipoVariacao = this.tiposvariacoes[i].id
}
}
this.listaValoresAtributo(this.idTipoVariacao);
}
listaValoresAtributo(id: number){
console.log(id)
this.tipoProdutoService.listaValoresAtributo(id)
.pipe(
take(1)
)
.subscribe((res) => {
console.log(res);
this.listaAtributos = res.data.valores_atributos;
this.loadingfiltro = false;
},
(err: HttpErrorResponse) => {
if (err.status == 401) {
this.authService.Logout();
}
if (err.error.data.erro) {
this.toastrService.showToast(false, 'Ops, temos um problema', err.error.data.erro);
} else {
this.toastrService.showToast(false, 'Ops, temos um problema', 'Entre em contato com o suporte!');
}
})
}
Everythings work well, this function take the id of my variation and send to my backend, that me returns an array (this.listaAtributos), i have to copulate the other select.
In my second select i do one ngfor trying to copulate the options according the answer of my server, but no one data is copulate. If i print a console.log in this.listaAtributos, i see my array with my data that i need to coppulate. How can i do this?
My second select:
<div class="col-md-2">
<div class="select">
<select formControlName="valor" class="select-text">
<option class="dropdown-item" selected>{{item.value.valor || 'Valor'}}</option>
<option *ngFor="let ValorAtributo of listaAtributos;let x = index"
class="dropdown-item">{{ValorAtributo.valor}}</option>
</select>
<span class="select-highlight"></span>
<span class="select-bar"></span>
</div>
</div>
Observables? Someone can teach me?
angular typescript
i have this select:
Template:
<div class="select">
<select (change)="getIdTipoVariacao(item.value.tipo)" formControlName="tipo" class="select-text">
<option class="dropdown-item" selected>{{item.value.tipo || 'Tipo da Variação'}}</option>
<option [hidden]="item.value.tipo == tipoVariacao.valor" *ngFor="let tipoVariacao of tiposvariacoes;let j = index"
class="dropdown-item">{{tipoVariacao.valor}}</option>
</select>
<span class="select-highlight"></span>
<span class="select-bar"></span>
</div>
In my component, throught the function getIdTipoVariacao() i catch the id of my "variacao" selected:
getIdTipoVariacao(variacao:string) { // take the id of one "tipo de variação" to send to function get-lista-valor-atributo to get the list of attributs of my "variation":
for(let i=0;i<this.tiposvariacoes.length;i++){
if(this.tiposvariacoes[i].valor == variacao){
this.idTipoVariacao = this.tiposvariacoes[i].id
}
}
this.listaValoresAtributo(this.idTipoVariacao);
}
listaValoresAtributo(id: number){
console.log(id)
this.tipoProdutoService.listaValoresAtributo(id)
.pipe(
take(1)
)
.subscribe((res) => {
console.log(res);
this.listaAtributos = res.data.valores_atributos;
this.loadingfiltro = false;
},
(err: HttpErrorResponse) => {
if (err.status == 401) {
this.authService.Logout();
}
if (err.error.data.erro) {
this.toastrService.showToast(false, 'Ops, temos um problema', err.error.data.erro);
} else {
this.toastrService.showToast(false, 'Ops, temos um problema', 'Entre em contato com o suporte!');
}
})
}
Everythings work well, this function take the id of my variation and send to my backend, that me returns an array (this.listaAtributos), i have to copulate the other select.
In my second select i do one ngfor trying to copulate the options according the answer of my server, but no one data is copulate. If i print a console.log in this.listaAtributos, i see my array with my data that i need to coppulate. How can i do this?
My second select:
<div class="col-md-2">
<div class="select">
<select formControlName="valor" class="select-text">
<option class="dropdown-item" selected>{{item.value.valor || 'Valor'}}</option>
<option *ngFor="let ValorAtributo of listaAtributos;let x = index"
class="dropdown-item">{{ValorAtributo.valor}}</option>
</select>
<span class="select-highlight"></span>
<span class="select-bar"></span>
</div>
</div>
Observables? Someone can teach me?
angular typescript
angular typescript
asked Nov 5 at 17:40
Renato Veronese
277
277
What do you see in the options ?
– Sunil Singh
Nov 5 at 17:59
my options is empty
– Renato Veronese
Nov 5 at 18:28
Your code is looking fine to me. Are you getting any error in console ?
– Sunil Singh
Nov 5 at 18:50
Can you verify if the listaAtributos is actually a list(array) and not an object
– Sachin Gupta
Nov 5 at 19:17
add a comment |
What do you see in the options ?
– Sunil Singh
Nov 5 at 17:59
my options is empty
– Renato Veronese
Nov 5 at 18:28
Your code is looking fine to me. Are you getting any error in console ?
– Sunil Singh
Nov 5 at 18:50
Can you verify if the listaAtributos is actually a list(array) and not an object
– Sachin Gupta
Nov 5 at 19:17
What do you see in the options ?
– Sunil Singh
Nov 5 at 17:59
What do you see in the options ?
– Sunil Singh
Nov 5 at 17:59
my options is empty
– Renato Veronese
Nov 5 at 18:28
my options is empty
– Renato Veronese
Nov 5 at 18:28
Your code is looking fine to me. Are you getting any error in console ?
– Sunil Singh
Nov 5 at 18:50
Your code is looking fine to me. Are you getting any error in console ?
– Sunil Singh
Nov 5 at 18:50
Can you verify if the listaAtributos is actually a list(array) and not an object
– Sachin Gupta
Nov 5 at 19:17
Can you verify if the listaAtributos is actually a list(array) and not an object
– Sachin Gupta
Nov 5 at 19:17
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53159467%2frefresh-select-options-in-angular-utilizing-two-selects%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Z3sf47Xlw46XauSOyf4uwnp7AH,Cw0,rYYkGxz,CRXRSnYOs,fW4,9Cwgq
What do you see in the options ?
– Sunil Singh
Nov 5 at 17:59
my options is empty
– Renato Veronese
Nov 5 at 18:28
Your code is looking fine to me. Are you getting any error in console ?
– Sunil Singh
Nov 5 at 18:50
Can you verify if the listaAtributos is actually a list(array) and not an object
– Sachin Gupta
Nov 5 at 19:17