How to bind Mongoose model with angularjs Checkbox How to bind Mongoose model with angularjs Checkbox mongoose mongoose

How to bind Mongoose model with angularjs Checkbox


What does your model look like? I would suggest using a ui-select https://github.com/angular-ui/ui-select instead of the multiple checkboxes as it is much cleaner UX and less controller code to maintain. Then you can create an enumeration of roles and that can be managed and all your code will continue to use that enumeration of roles. Much easier to manage.

angular.module('globals', [])  .constant('Roles', ['USR', 'ADM', 'SAD']);

Here is my property in the User Model:

  roles: {    type: Array,    default: ['USR']  }

In my controller scope the roles OR use dependency injection to load the global enumerations / roles as described above:

$scope.rolesNames = ['USR', 'ADM', 'SAD];

For the Front End / Angular I use a UI-select

  {{user}}  <br/>             <ui-select multiple ng-model="user.roles" theme="select2" ng-disabled="disabled" style="width: 300px;">            <ui-select-match placeholder="Select roles...">{{ $item }}</ui-select-match>            <ui-select-choices repeat="role in rolesNames">              {{ role }}            </ui-select-choices>          </ui-select>