It appears that the users: UsersModel[]
array in your component has not been initialized, resulting in it being undefined
. As a result, you are attempting to access the length
property of an undefined object/array. To address this issue, consider disabling the button if the users
array has not been initialized or if its length is 0:
<button type="button" [disabled]="!users || users.length === 0">Send Mass Emails</button>
You can see a demonstration of this behavior in action on this plunkr link.
An alternative solution would be to initialize the user
array as an empty array in your component:
users: UsersModel[] = [];
This way, you can easily disable or enable the button based on whether the user array's length is zero/false:
<button type="button" [disabled]="!user.length">Send mass emails</button>
You can see how initializing the users
array to an empty array and checking its length can help in enabling/disabling the button in this plunkr example.
I hope this information proves helpful!