Refresh select options in angular utilizing two selects











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?










share|improve this question






















  • 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















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?










share|improve this question






















  • 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













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?










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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


















  • 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

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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





































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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




















































































這個網誌中的熱門文章

Hercules Kyvelos

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud