Simple not working. No error in IDE or browser
I am a student trying to learn angular but having some trouble so sorry if this is a stupid question.
Basically I have a mat-form-field with a mat-select. The mat-select shows up in the browser but the options do not drop down. Here's the html and .ts
HTML:
<mat-form-field>
<mat-select placeholder="Gender">
<mat-option *ngFor="let Gender of genders" [value]="Gender.value">
{{Gender.viewValue}}
</mat-option>
</mat-select>
</mat-form-field>
<!--Form for Gender-->
.ts:
export interface Gender {
value: string;
viewValue: string;
}
export class SelectGender {
genders: Gender = [
{ value: 'm', viewValue: 'Male' },
{ value: 'f', viewValue: 'Female' },];}
I have all the Imports already working, but here's the app.module.ts incase:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { PostDetailsComponent } from './post-details/post-details.component';
import { PostService } from './services/post.service';
import { HttpClientModule } from '@angular/common/http';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { RouterModule, Routes } from '@angular/router';
import { FormsModule } from "@angular/forms";
import {
MatInputModule,
MatMenuModule,
MatCardModule,
MatButtonModule,
MatIconModule,
MatToolbarModule,
MatExpansionModule,
DateAdapter,
MatFormFieldModule,
MatNativeDateModule,
MatSelectModule,
} from '@angular/material';
import { MatDatepickerModule } from '@angular/material/datepicker';
import { MatRadioModule } from '@angular/material/radio';
import { PostCreateComponent } from './post-create/post-create.component';
import { PostEditComponent } from './post-edit/post-edit.component';
import { PostSigninComponent } from './post-signin/post-signin.component';
import { MembershipTypesComponent } from './membership-types/membership-types.component';
const appRoutes: Routes = [
{
path: 'list',
component: PostDetailsComponent
},
{
path: 'create',
component: PostCreateComponent
},
{
path: 'edit/:id',
component: PostEditComponent
},
{
path: 'membershipTypes',
component: MembershipTypesComponent
}
];
@NgModule({
declarations: [
AppComponent,
PostDetailsComponent,
PostCreateComponent,
PostEditComponent,
PostSigninComponent,
MembershipTypesComponent
],
imports: [
RouterModule.forRoot(appRoutes),
BrowserModule,
FormsModule,
HttpClientModule,
MatIconModule,
MatButtonModule,
BrowserAnimationsModule,
MatInputModule,
MatFormFieldModule,
MatCardModule,
MatButtonModule,
MatToolbarModule,
MatExpansionModule,
MatMenuModule,
MatSelectModule, //imported for gender picker + membership type
MatDatepickerModule, //imported for datepicker
MatNativeDateModule, //for date picker
MatRadioModule//radio buttons
],
providers: [PostService],
bootstrap: [AppComponent]
})
export class AppModule { }
Adding in entire component.ts
import { Component, OnInit } from '@angular/core';
import { NgForm } from "@angular/forms";
import { PostService } from '../services/post.service';
import { MatSelectModule } from '@angular/material/select';
@Component({
selector: 'app-post-create',
templateUrl: './post-create.component.html',
styleUrls: ['./post-create.component.css'],
})
export class PostCreateComponent implements OnInit {
constructor(private service: PostService) { }
onAddPost(form: NgForm) {
this.service.addPost(form.value.FirstName, form.value.SurName, form.value.Address, form.value.phoneNumber).subscribe();
//when adding anything here make sure to add it to post.service as well as post.model.ts and server.js/app.post
console.log(form.value);
form.resetForm();
}
ngOnInit() {
}
} export interface Gender {
value: string;
viewValue: string;
}
export class SelectOverviewExample {
genders: Gender = [
{ value: 'm', viewValue: 'Male' },
{ value: 'f', viewValue: 'Female' }
]
}
export interface type {
value: string;
viewValue: string;
}
export class MembershipType {
types: type = [
{ value: '1day', viewValue: 'Single Session : €8 / €6.40' },
{ value: '1month', viewValue: '1 month: €30/€24' },
{ value: '3months', viewValue: '3 month: €75/ €60' },
{ value: '6months', viewValue: '6 month: €129/ €103' },
{ value: '12Months', viewValue: '12 month: €199/ €160' },
];
}
I've been at it for a while and its probably a stupid Mistake but any help would be appreciated thanks
html angular
|
show 4 more comments
I am a student trying to learn angular but having some trouble so sorry if this is a stupid question.
Basically I have a mat-form-field with a mat-select. The mat-select shows up in the browser but the options do not drop down. Here's the html and .ts
HTML:
<mat-form-field>
<mat-select placeholder="Gender">
<mat-option *ngFor="let Gender of genders" [value]="Gender.value">
{{Gender.viewValue}}
</mat-option>
</mat-select>
</mat-form-field>
<!--Form for Gender-->
.ts:
export interface Gender {
value: string;
viewValue: string;
}
export class SelectGender {
genders: Gender = [
{ value: 'm', viewValue: 'Male' },
{ value: 'f', viewValue: 'Female' },];}
I have all the Imports already working, but here's the app.module.ts incase:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { PostDetailsComponent } from './post-details/post-details.component';
import { PostService } from './services/post.service';
import { HttpClientModule } from '@angular/common/http';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { RouterModule, Routes } from '@angular/router';
import { FormsModule } from "@angular/forms";
import {
MatInputModule,
MatMenuModule,
MatCardModule,
MatButtonModule,
MatIconModule,
MatToolbarModule,
MatExpansionModule,
DateAdapter,
MatFormFieldModule,
MatNativeDateModule,
MatSelectModule,
} from '@angular/material';
import { MatDatepickerModule } from '@angular/material/datepicker';
import { MatRadioModule } from '@angular/material/radio';
import { PostCreateComponent } from './post-create/post-create.component';
import { PostEditComponent } from './post-edit/post-edit.component';
import { PostSigninComponent } from './post-signin/post-signin.component';
import { MembershipTypesComponent } from './membership-types/membership-types.component';
const appRoutes: Routes = [
{
path: 'list',
component: PostDetailsComponent
},
{
path: 'create',
component: PostCreateComponent
},
{
path: 'edit/:id',
component: PostEditComponent
},
{
path: 'membershipTypes',
component: MembershipTypesComponent
}
];
@NgModule({
declarations: [
AppComponent,
PostDetailsComponent,
PostCreateComponent,
PostEditComponent,
PostSigninComponent,
MembershipTypesComponent
],
imports: [
RouterModule.forRoot(appRoutes),
BrowserModule,
FormsModule,
HttpClientModule,
MatIconModule,
MatButtonModule,
BrowserAnimationsModule,
MatInputModule,
MatFormFieldModule,
MatCardModule,
MatButtonModule,
MatToolbarModule,
MatExpansionModule,
MatMenuModule,
MatSelectModule, //imported for gender picker + membership type
MatDatepickerModule, //imported for datepicker
MatNativeDateModule, //for date picker
MatRadioModule//radio buttons
],
providers: [PostService],
bootstrap: [AppComponent]
})
export class AppModule { }
Adding in entire component.ts
import { Component, OnInit } from '@angular/core';
import { NgForm } from "@angular/forms";
import { PostService } from '../services/post.service';
import { MatSelectModule } from '@angular/material/select';
@Component({
selector: 'app-post-create',
templateUrl: './post-create.component.html',
styleUrls: ['./post-create.component.css'],
})
export class PostCreateComponent implements OnInit {
constructor(private service: PostService) { }
onAddPost(form: NgForm) {
this.service.addPost(form.value.FirstName, form.value.SurName, form.value.Address, form.value.phoneNumber).subscribe();
//when adding anything here make sure to add it to post.service as well as post.model.ts and server.js/app.post
console.log(form.value);
form.resetForm();
}
ngOnInit() {
}
} export interface Gender {
value: string;
viewValue: string;
}
export class SelectOverviewExample {
genders: Gender = [
{ value: 'm', viewValue: 'Male' },
{ value: 'f', viewValue: 'Female' }
]
}
export interface type {
value: string;
viewValue: string;
}
export class MembershipType {
types: type = [
{ value: '1day', viewValue: 'Single Session : €8 / €6.40' },
{ value: '1month', viewValue: '1 month: €30/€24' },
{ value: '3months', viewValue: '3 month: €75/ €60' },
{ value: '6months', viewValue: '6 month: €129/ €103' },
{ value: '12Months', viewValue: '12 month: €199/ €160' },
];
}
I've been at it for a while and its probably a stupid Mistake but any help would be appreciated thanks
html angular
*ngFor="let Gender of Genders"
where isGenders
in ts? I see onlygenders
– Smollet777
Nov 20 at 16:24
@Smollet777 Yeah Sorry, I had realized that, and changed it to the lower case, not the problem unfortunately. I'll edit that
– Jack Caltagirone
Nov 20 at 16:26
did you import the modules in module.ts that is related to component.ts which has this mat-select?
– yer
Nov 20 at 16:30
Seems to be working fine to me - check out this working StackBlitz
– Narm
Nov 20 at 16:35
Yeah I did, they're in the app.module.ts as "MatSelectModule } from '(at)angular/material'; " and "MatSelectModule" in the (at)ngmodule imports @yer
– Jack Caltagirone
Nov 20 at 16:35
|
show 4 more comments
I am a student trying to learn angular but having some trouble so sorry if this is a stupid question.
Basically I have a mat-form-field with a mat-select. The mat-select shows up in the browser but the options do not drop down. Here's the html and .ts
HTML:
<mat-form-field>
<mat-select placeholder="Gender">
<mat-option *ngFor="let Gender of genders" [value]="Gender.value">
{{Gender.viewValue}}
</mat-option>
</mat-select>
</mat-form-field>
<!--Form for Gender-->
.ts:
export interface Gender {
value: string;
viewValue: string;
}
export class SelectGender {
genders: Gender = [
{ value: 'm', viewValue: 'Male' },
{ value: 'f', viewValue: 'Female' },];}
I have all the Imports already working, but here's the app.module.ts incase:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { PostDetailsComponent } from './post-details/post-details.component';
import { PostService } from './services/post.service';
import { HttpClientModule } from '@angular/common/http';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { RouterModule, Routes } from '@angular/router';
import { FormsModule } from "@angular/forms";
import {
MatInputModule,
MatMenuModule,
MatCardModule,
MatButtonModule,
MatIconModule,
MatToolbarModule,
MatExpansionModule,
DateAdapter,
MatFormFieldModule,
MatNativeDateModule,
MatSelectModule,
} from '@angular/material';
import { MatDatepickerModule } from '@angular/material/datepicker';
import { MatRadioModule } from '@angular/material/radio';
import { PostCreateComponent } from './post-create/post-create.component';
import { PostEditComponent } from './post-edit/post-edit.component';
import { PostSigninComponent } from './post-signin/post-signin.component';
import { MembershipTypesComponent } from './membership-types/membership-types.component';
const appRoutes: Routes = [
{
path: 'list',
component: PostDetailsComponent
},
{
path: 'create',
component: PostCreateComponent
},
{
path: 'edit/:id',
component: PostEditComponent
},
{
path: 'membershipTypes',
component: MembershipTypesComponent
}
];
@NgModule({
declarations: [
AppComponent,
PostDetailsComponent,
PostCreateComponent,
PostEditComponent,
PostSigninComponent,
MembershipTypesComponent
],
imports: [
RouterModule.forRoot(appRoutes),
BrowserModule,
FormsModule,
HttpClientModule,
MatIconModule,
MatButtonModule,
BrowserAnimationsModule,
MatInputModule,
MatFormFieldModule,
MatCardModule,
MatButtonModule,
MatToolbarModule,
MatExpansionModule,
MatMenuModule,
MatSelectModule, //imported for gender picker + membership type
MatDatepickerModule, //imported for datepicker
MatNativeDateModule, //for date picker
MatRadioModule//radio buttons
],
providers: [PostService],
bootstrap: [AppComponent]
})
export class AppModule { }
Adding in entire component.ts
import { Component, OnInit } from '@angular/core';
import { NgForm } from "@angular/forms";
import { PostService } from '../services/post.service';
import { MatSelectModule } from '@angular/material/select';
@Component({
selector: 'app-post-create',
templateUrl: './post-create.component.html',
styleUrls: ['./post-create.component.css'],
})
export class PostCreateComponent implements OnInit {
constructor(private service: PostService) { }
onAddPost(form: NgForm) {
this.service.addPost(form.value.FirstName, form.value.SurName, form.value.Address, form.value.phoneNumber).subscribe();
//when adding anything here make sure to add it to post.service as well as post.model.ts and server.js/app.post
console.log(form.value);
form.resetForm();
}
ngOnInit() {
}
} export interface Gender {
value: string;
viewValue: string;
}
export class SelectOverviewExample {
genders: Gender = [
{ value: 'm', viewValue: 'Male' },
{ value: 'f', viewValue: 'Female' }
]
}
export interface type {
value: string;
viewValue: string;
}
export class MembershipType {
types: type = [
{ value: '1day', viewValue: 'Single Session : €8 / €6.40' },
{ value: '1month', viewValue: '1 month: €30/€24' },
{ value: '3months', viewValue: '3 month: €75/ €60' },
{ value: '6months', viewValue: '6 month: €129/ €103' },
{ value: '12Months', viewValue: '12 month: €199/ €160' },
];
}
I've been at it for a while and its probably a stupid Mistake but any help would be appreciated thanks
html angular
I am a student trying to learn angular but having some trouble so sorry if this is a stupid question.
Basically I have a mat-form-field with a mat-select. The mat-select shows up in the browser but the options do not drop down. Here's the html and .ts
HTML:
<mat-form-field>
<mat-select placeholder="Gender">
<mat-option *ngFor="let Gender of genders" [value]="Gender.value">
{{Gender.viewValue}}
</mat-option>
</mat-select>
</mat-form-field>
<!--Form for Gender-->
.ts:
export interface Gender {
value: string;
viewValue: string;
}
export class SelectGender {
genders: Gender = [
{ value: 'm', viewValue: 'Male' },
{ value: 'f', viewValue: 'Female' },];}
I have all the Imports already working, but here's the app.module.ts incase:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { PostDetailsComponent } from './post-details/post-details.component';
import { PostService } from './services/post.service';
import { HttpClientModule } from '@angular/common/http';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { RouterModule, Routes } from '@angular/router';
import { FormsModule } from "@angular/forms";
import {
MatInputModule,
MatMenuModule,
MatCardModule,
MatButtonModule,
MatIconModule,
MatToolbarModule,
MatExpansionModule,
DateAdapter,
MatFormFieldModule,
MatNativeDateModule,
MatSelectModule,
} from '@angular/material';
import { MatDatepickerModule } from '@angular/material/datepicker';
import { MatRadioModule } from '@angular/material/radio';
import { PostCreateComponent } from './post-create/post-create.component';
import { PostEditComponent } from './post-edit/post-edit.component';
import { PostSigninComponent } from './post-signin/post-signin.component';
import { MembershipTypesComponent } from './membership-types/membership-types.component';
const appRoutes: Routes = [
{
path: 'list',
component: PostDetailsComponent
},
{
path: 'create',
component: PostCreateComponent
},
{
path: 'edit/:id',
component: PostEditComponent
},
{
path: 'membershipTypes',
component: MembershipTypesComponent
}
];
@NgModule({
declarations: [
AppComponent,
PostDetailsComponent,
PostCreateComponent,
PostEditComponent,
PostSigninComponent,
MembershipTypesComponent
],
imports: [
RouterModule.forRoot(appRoutes),
BrowserModule,
FormsModule,
HttpClientModule,
MatIconModule,
MatButtonModule,
BrowserAnimationsModule,
MatInputModule,
MatFormFieldModule,
MatCardModule,
MatButtonModule,
MatToolbarModule,
MatExpansionModule,
MatMenuModule,
MatSelectModule, //imported for gender picker + membership type
MatDatepickerModule, //imported for datepicker
MatNativeDateModule, //for date picker
MatRadioModule//radio buttons
],
providers: [PostService],
bootstrap: [AppComponent]
})
export class AppModule { }
Adding in entire component.ts
import { Component, OnInit } from '@angular/core';
import { NgForm } from "@angular/forms";
import { PostService } from '../services/post.service';
import { MatSelectModule } from '@angular/material/select';
@Component({
selector: 'app-post-create',
templateUrl: './post-create.component.html',
styleUrls: ['./post-create.component.css'],
})
export class PostCreateComponent implements OnInit {
constructor(private service: PostService) { }
onAddPost(form: NgForm) {
this.service.addPost(form.value.FirstName, form.value.SurName, form.value.Address, form.value.phoneNumber).subscribe();
//when adding anything here make sure to add it to post.service as well as post.model.ts and server.js/app.post
console.log(form.value);
form.resetForm();
}
ngOnInit() {
}
} export interface Gender {
value: string;
viewValue: string;
}
export class SelectOverviewExample {
genders: Gender = [
{ value: 'm', viewValue: 'Male' },
{ value: 'f', viewValue: 'Female' }
]
}
export interface type {
value: string;
viewValue: string;
}
export class MembershipType {
types: type = [
{ value: '1day', viewValue: 'Single Session : €8 / €6.40' },
{ value: '1month', viewValue: '1 month: €30/€24' },
{ value: '3months', viewValue: '3 month: €75/ €60' },
{ value: '6months', viewValue: '6 month: €129/ €103' },
{ value: '12Months', viewValue: '12 month: €199/ €160' },
];
}
I've been at it for a while and its probably a stupid Mistake but any help would be appreciated thanks
html angular
html angular
edited Nov 20 at 16:45
asked Nov 20 at 16:19
Jack Caltagirone
104
104
*ngFor="let Gender of Genders"
where isGenders
in ts? I see onlygenders
– Smollet777
Nov 20 at 16:24
@Smollet777 Yeah Sorry, I had realized that, and changed it to the lower case, not the problem unfortunately. I'll edit that
– Jack Caltagirone
Nov 20 at 16:26
did you import the modules in module.ts that is related to component.ts which has this mat-select?
– yer
Nov 20 at 16:30
Seems to be working fine to me - check out this working StackBlitz
– Narm
Nov 20 at 16:35
Yeah I did, they're in the app.module.ts as "MatSelectModule } from '(at)angular/material'; " and "MatSelectModule" in the (at)ngmodule imports @yer
– Jack Caltagirone
Nov 20 at 16:35
|
show 4 more comments
*ngFor="let Gender of Genders"
where isGenders
in ts? I see onlygenders
– Smollet777
Nov 20 at 16:24
@Smollet777 Yeah Sorry, I had realized that, and changed it to the lower case, not the problem unfortunately. I'll edit that
– Jack Caltagirone
Nov 20 at 16:26
did you import the modules in module.ts that is related to component.ts which has this mat-select?
– yer
Nov 20 at 16:30
Seems to be working fine to me - check out this working StackBlitz
– Narm
Nov 20 at 16:35
Yeah I did, they're in the app.module.ts as "MatSelectModule } from '(at)angular/material'; " and "MatSelectModule" in the (at)ngmodule imports @yer
– Jack Caltagirone
Nov 20 at 16:35
*ngFor="let Gender of Genders"
where is Genders
in ts? I see only genders
– Smollet777
Nov 20 at 16:24
*ngFor="let Gender of Genders"
where is Genders
in ts? I see only genders
– Smollet777
Nov 20 at 16:24
@Smollet777 Yeah Sorry, I had realized that, and changed it to the lower case, not the problem unfortunately. I'll edit that
– Jack Caltagirone
Nov 20 at 16:26
@Smollet777 Yeah Sorry, I had realized that, and changed it to the lower case, not the problem unfortunately. I'll edit that
– Jack Caltagirone
Nov 20 at 16:26
did you import the modules in module.ts that is related to component.ts which has this mat-select?
– yer
Nov 20 at 16:30
did you import the modules in module.ts that is related to component.ts which has this mat-select?
– yer
Nov 20 at 16:30
Seems to be working fine to me - check out this working StackBlitz
– Narm
Nov 20 at 16:35
Seems to be working fine to me - check out this working StackBlitz
– Narm
Nov 20 at 16:35
Yeah I did, they're in the app.module.ts as "MatSelectModule } from '(at)angular/material'; " and "MatSelectModule" in the (at)ngmodule imports @yer
– Jack Caltagirone
Nov 20 at 16:35
Yeah I did, they're in the app.module.ts as "MatSelectModule } from '(at)angular/material'; " and "MatSelectModule" in the (at)ngmodule imports @yer
– Jack Caltagirone
Nov 20 at 16:35
|
show 4 more comments
2 Answers
2
active
oldest
votes
I think that was because of your component SelectGender
, seems it was not declared in your @NgModule
metadata.
PS: also I do not see any@Component
decorator, in that way it is considered as a model more than a component, unless you forget to paste that part.
Here is a working stackblitz where the AppComponent
is your SelectGender
.
UPDATE:
For your updated question, assuming your HTML snippet is a part of post-create.component.html
, that wont work since you're trying loop over values that doesnt even exist on the relevant TS part (PostCreateComponent
), you move :
genders: Gender = [
{ value: 'm', viewValue: 'Male' },
{ value: 'f', viewValue: 'Female' }
]
To PostCreateComponent
Ts part merely.
Sorry, I'm fairly new to it all, But through your stackblitz I can't find where you added the SelectGender in the NgModule.
– Jack Caltagirone
Nov 20 at 16:49
@JackCaltagirone see updated answer , and for your question I'd mentioned that afterPS
.. :)
– selem mn
Nov 20 at 16:54
Sorry again, but I havegenders: Gender = [ { value: 'm', viewValue: 'Male' }, { value: 'f', viewValue: 'Female' } ]
In the PostCreateComponent .ts. I only have a calling of that GenderArray in the html edit: I'm an idiot at formatting
– Jack Caltagirone
Nov 20 at 17:04
1
Messed around with it a bit, you were right. changed it, all is well. Thank you selem saved me a few hours
– Jack Caltagirone
Nov 20 at 17:05
@JackCaltagirone welcome :)
– selem mn
Nov 20 at 22:40
add a comment |
You have to add this in your component class PostCreateComponent, not outside the component class. Since you declared it outside the component class, it won't be part of the component and that's why you were not able to see the options
genders: Gender = [
{ value: 'm', viewValue: 'Male' },
{ value: 'f', viewValue: 'Female' }
]
Which goes like this:
export class PostCreateComponent implements OnInit {
constructor(private service: PostService) { }
genders: Gender = [
{ value: 'm', viewValue: 'Male' },
{ value: 'f', viewValue: 'Female' }
]
onAddPost(form: NgForm) {
this.service.addPost(form.value.FirstName, form.value.SurName, form.value.Address, form.value.phoneNumber).subscribe();
//when adding anything here make sure to add it to post.service as well as post.model.ts and server.js/app.post
console.log(form.value);
form.resetForm();
}
ngOnInit() {
}
}
add a comment |
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',
autoActivateHeartbeat: false,
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
});
}
});
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53397218%2fsimple-mat-option-not-working-no-error-in-ide-or-browser%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I think that was because of your component SelectGender
, seems it was not declared in your @NgModule
metadata.
PS: also I do not see any@Component
decorator, in that way it is considered as a model more than a component, unless you forget to paste that part.
Here is a working stackblitz where the AppComponent
is your SelectGender
.
UPDATE:
For your updated question, assuming your HTML snippet is a part of post-create.component.html
, that wont work since you're trying loop over values that doesnt even exist on the relevant TS part (PostCreateComponent
), you move :
genders: Gender = [
{ value: 'm', viewValue: 'Male' },
{ value: 'f', viewValue: 'Female' }
]
To PostCreateComponent
Ts part merely.
Sorry, I'm fairly new to it all, But through your stackblitz I can't find where you added the SelectGender in the NgModule.
– Jack Caltagirone
Nov 20 at 16:49
@JackCaltagirone see updated answer , and for your question I'd mentioned that afterPS
.. :)
– selem mn
Nov 20 at 16:54
Sorry again, but I havegenders: Gender = [ { value: 'm', viewValue: 'Male' }, { value: 'f', viewValue: 'Female' } ]
In the PostCreateComponent .ts. I only have a calling of that GenderArray in the html edit: I'm an idiot at formatting
– Jack Caltagirone
Nov 20 at 17:04
1
Messed around with it a bit, you were right. changed it, all is well. Thank you selem saved me a few hours
– Jack Caltagirone
Nov 20 at 17:05
@JackCaltagirone welcome :)
– selem mn
Nov 20 at 22:40
add a comment |
I think that was because of your component SelectGender
, seems it was not declared in your @NgModule
metadata.
PS: also I do not see any@Component
decorator, in that way it is considered as a model more than a component, unless you forget to paste that part.
Here is a working stackblitz where the AppComponent
is your SelectGender
.
UPDATE:
For your updated question, assuming your HTML snippet is a part of post-create.component.html
, that wont work since you're trying loop over values that doesnt even exist on the relevant TS part (PostCreateComponent
), you move :
genders: Gender = [
{ value: 'm', viewValue: 'Male' },
{ value: 'f', viewValue: 'Female' }
]
To PostCreateComponent
Ts part merely.
Sorry, I'm fairly new to it all, But through your stackblitz I can't find where you added the SelectGender in the NgModule.
– Jack Caltagirone
Nov 20 at 16:49
@JackCaltagirone see updated answer , and for your question I'd mentioned that afterPS
.. :)
– selem mn
Nov 20 at 16:54
Sorry again, but I havegenders: Gender = [ { value: 'm', viewValue: 'Male' }, { value: 'f', viewValue: 'Female' } ]
In the PostCreateComponent .ts. I only have a calling of that GenderArray in the html edit: I'm an idiot at formatting
– Jack Caltagirone
Nov 20 at 17:04
1
Messed around with it a bit, you were right. changed it, all is well. Thank you selem saved me a few hours
– Jack Caltagirone
Nov 20 at 17:05
@JackCaltagirone welcome :)
– selem mn
Nov 20 at 22:40
add a comment |
I think that was because of your component SelectGender
, seems it was not declared in your @NgModule
metadata.
PS: also I do not see any@Component
decorator, in that way it is considered as a model more than a component, unless you forget to paste that part.
Here is a working stackblitz where the AppComponent
is your SelectGender
.
UPDATE:
For your updated question, assuming your HTML snippet is a part of post-create.component.html
, that wont work since you're trying loop over values that doesnt even exist on the relevant TS part (PostCreateComponent
), you move :
genders: Gender = [
{ value: 'm', viewValue: 'Male' },
{ value: 'f', viewValue: 'Female' }
]
To PostCreateComponent
Ts part merely.
I think that was because of your component SelectGender
, seems it was not declared in your @NgModule
metadata.
PS: also I do not see any@Component
decorator, in that way it is considered as a model more than a component, unless you forget to paste that part.
Here is a working stackblitz where the AppComponent
is your SelectGender
.
UPDATE:
For your updated question, assuming your HTML snippet is a part of post-create.component.html
, that wont work since you're trying loop over values that doesnt even exist on the relevant TS part (PostCreateComponent
), you move :
genders: Gender = [
{ value: 'm', viewValue: 'Male' },
{ value: 'f', viewValue: 'Female' }
]
To PostCreateComponent
Ts part merely.
edited Nov 20 at 17:21
answered Nov 20 at 16:40
selem mn
4,67541939
4,67541939
Sorry, I'm fairly new to it all, But through your stackblitz I can't find where you added the SelectGender in the NgModule.
– Jack Caltagirone
Nov 20 at 16:49
@JackCaltagirone see updated answer , and for your question I'd mentioned that afterPS
.. :)
– selem mn
Nov 20 at 16:54
Sorry again, but I havegenders: Gender = [ { value: 'm', viewValue: 'Male' }, { value: 'f', viewValue: 'Female' } ]
In the PostCreateComponent .ts. I only have a calling of that GenderArray in the html edit: I'm an idiot at formatting
– Jack Caltagirone
Nov 20 at 17:04
1
Messed around with it a bit, you were right. changed it, all is well. Thank you selem saved me a few hours
– Jack Caltagirone
Nov 20 at 17:05
@JackCaltagirone welcome :)
– selem mn
Nov 20 at 22:40
add a comment |
Sorry, I'm fairly new to it all, But through your stackblitz I can't find where you added the SelectGender in the NgModule.
– Jack Caltagirone
Nov 20 at 16:49
@JackCaltagirone see updated answer , and for your question I'd mentioned that afterPS
.. :)
– selem mn
Nov 20 at 16:54
Sorry again, but I havegenders: Gender = [ { value: 'm', viewValue: 'Male' }, { value: 'f', viewValue: 'Female' } ]
In the PostCreateComponent .ts. I only have a calling of that GenderArray in the html edit: I'm an idiot at formatting
– Jack Caltagirone
Nov 20 at 17:04
1
Messed around with it a bit, you were right. changed it, all is well. Thank you selem saved me a few hours
– Jack Caltagirone
Nov 20 at 17:05
@JackCaltagirone welcome :)
– selem mn
Nov 20 at 22:40
Sorry, I'm fairly new to it all, But through your stackblitz I can't find where you added the SelectGender in the NgModule.
– Jack Caltagirone
Nov 20 at 16:49
Sorry, I'm fairly new to it all, But through your stackblitz I can't find where you added the SelectGender in the NgModule.
– Jack Caltagirone
Nov 20 at 16:49
@JackCaltagirone see updated answer , and for your question I'd mentioned that after
PS
.. :)– selem mn
Nov 20 at 16:54
@JackCaltagirone see updated answer , and for your question I'd mentioned that after
PS
.. :)– selem mn
Nov 20 at 16:54
Sorry again, but I have
genders: Gender = [ { value: 'm', viewValue: 'Male' }, { value: 'f', viewValue: 'Female' } ]
In the PostCreateComponent .ts. I only have a calling of that GenderArray in the html edit: I'm an idiot at formatting– Jack Caltagirone
Nov 20 at 17:04
Sorry again, but I have
genders: Gender = [ { value: 'm', viewValue: 'Male' }, { value: 'f', viewValue: 'Female' } ]
In the PostCreateComponent .ts. I only have a calling of that GenderArray in the html edit: I'm an idiot at formatting– Jack Caltagirone
Nov 20 at 17:04
1
1
Messed around with it a bit, you were right. changed it, all is well. Thank you selem saved me a few hours
– Jack Caltagirone
Nov 20 at 17:05
Messed around with it a bit, you were right. changed it, all is well. Thank you selem saved me a few hours
– Jack Caltagirone
Nov 20 at 17:05
@JackCaltagirone welcome :)
– selem mn
Nov 20 at 22:40
@JackCaltagirone welcome :)
– selem mn
Nov 20 at 22:40
add a comment |
You have to add this in your component class PostCreateComponent, not outside the component class. Since you declared it outside the component class, it won't be part of the component and that's why you were not able to see the options
genders: Gender = [
{ value: 'm', viewValue: 'Male' },
{ value: 'f', viewValue: 'Female' }
]
Which goes like this:
export class PostCreateComponent implements OnInit {
constructor(private service: PostService) { }
genders: Gender = [
{ value: 'm', viewValue: 'Male' },
{ value: 'f', viewValue: 'Female' }
]
onAddPost(form: NgForm) {
this.service.addPost(form.value.FirstName, form.value.SurName, form.value.Address, form.value.phoneNumber).subscribe();
//when adding anything here make sure to add it to post.service as well as post.model.ts and server.js/app.post
console.log(form.value);
form.resetForm();
}
ngOnInit() {
}
}
add a comment |
You have to add this in your component class PostCreateComponent, not outside the component class. Since you declared it outside the component class, it won't be part of the component and that's why you were not able to see the options
genders: Gender = [
{ value: 'm', viewValue: 'Male' },
{ value: 'f', viewValue: 'Female' }
]
Which goes like this:
export class PostCreateComponent implements OnInit {
constructor(private service: PostService) { }
genders: Gender = [
{ value: 'm', viewValue: 'Male' },
{ value: 'f', viewValue: 'Female' }
]
onAddPost(form: NgForm) {
this.service.addPost(form.value.FirstName, form.value.SurName, form.value.Address, form.value.phoneNumber).subscribe();
//when adding anything here make sure to add it to post.service as well as post.model.ts and server.js/app.post
console.log(form.value);
form.resetForm();
}
ngOnInit() {
}
}
add a comment |
You have to add this in your component class PostCreateComponent, not outside the component class. Since you declared it outside the component class, it won't be part of the component and that's why you were not able to see the options
genders: Gender = [
{ value: 'm', viewValue: 'Male' },
{ value: 'f', viewValue: 'Female' }
]
Which goes like this:
export class PostCreateComponent implements OnInit {
constructor(private service: PostService) { }
genders: Gender = [
{ value: 'm', viewValue: 'Male' },
{ value: 'f', viewValue: 'Female' }
]
onAddPost(form: NgForm) {
this.service.addPost(form.value.FirstName, form.value.SurName, form.value.Address, form.value.phoneNumber).subscribe();
//when adding anything here make sure to add it to post.service as well as post.model.ts and server.js/app.post
console.log(form.value);
form.resetForm();
}
ngOnInit() {
}
}
You have to add this in your component class PostCreateComponent, not outside the component class. Since you declared it outside the component class, it won't be part of the component and that's why you were not able to see the options
genders: Gender = [
{ value: 'm', viewValue: 'Male' },
{ value: 'f', viewValue: 'Female' }
]
Which goes like this:
export class PostCreateComponent implements OnInit {
constructor(private service: PostService) { }
genders: Gender = [
{ value: 'm', viewValue: 'Male' },
{ value: 'f', viewValue: 'Female' }
]
onAddPost(form: NgForm) {
this.service.addPost(form.value.FirstName, form.value.SurName, form.value.Address, form.value.phoneNumber).subscribe();
//when adding anything here make sure to add it to post.service as well as post.model.ts and server.js/app.post
console.log(form.value);
form.resetForm();
}
ngOnInit() {
}
}
edited Nov 20 at 17:02
answered Nov 20 at 16:54
yer
536115
536115
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53397218%2fsimple-mat-option-not-working-no-error-in-ide-or-browser%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
*ngFor="let Gender of Genders"
where isGenders
in ts? I see onlygenders
– Smollet777
Nov 20 at 16:24
@Smollet777 Yeah Sorry, I had realized that, and changed it to the lower case, not the problem unfortunately. I'll edit that
– Jack Caltagirone
Nov 20 at 16:26
did you import the modules in module.ts that is related to component.ts which has this mat-select?
– yer
Nov 20 at 16:30
Seems to be working fine to me - check out this working StackBlitz
– Narm
Nov 20 at 16:35
Yeah I did, they're in the app.module.ts as "MatSelectModule } from '(at)angular/material'; " and "MatSelectModule" in the (at)ngmodule imports @yer
– Jack Caltagirone
Nov 20 at 16:35