I am trying to add a user (which succesfully works in the backend. users get added to my db) but my view will not update when the user is added to the db.
I am working with Angular and Node for my backend.
I must mention that my form for adding a user is in a popup box (md-dialog --> angular material) but this should not be an issue as to why the view won't update properly. The user will show up in the list once I refresh my browser.
my code for adding the user (app.js)
//Function to add a user to the db
$scope.inviteUser = function(){
$http.post('/api/users/invite', {
'email': $scope.user.email,
'role_id': $scope.user.role
}, {
headers: {
"Content-Type": "text/plain"
}
})
.success(function(data, status, headers, config) {
console.log("Successfully saved a user to the DB", data);
//$scope.userInfo = data;
$scope.userInfo.push(data);
})
.error(function(data, status, headers, config) {
console.log("Failed to add user to DB");
});
}
addUser.tmpl.html
<md-dialog aria-label="" ng-controller="CalendarCtrl">
<form name="form" >
<md-toolbar>
<div class="md-toolbar-tools">
<h1 class="customH1">Invite a user</h1>
<span flex></span>
<!-- <md-button class="md-icon-button" ng-click="closeDialog()">
<md-icon md-svg-src="images/ic_close_24px.svg" aria-label="Close dialog"></md-icon>
</md-button> -->
</div>
</md-toolbar>
<md-dialog-content>
<div id="containerForm">
<div layout="row">
<md-input-container flex="">
<div class="form-group" ng-class="{ 'has-success': form.email.$valid && submitted,'has-error': form.email.$invalid && submitted }">
<label>Enter the user's e-mail</label>
<input type="email" name="email" id="to" class="form-control" ng-model="user.email" required mongoose-error/>
<p class="help-block" ng-show="form.email.$error.email && submitted">
Doesn't look like a valid email.
</p>
<p class="help-block" ng-show="form.email.$error.required && submitted">
What's your email address?
</p>
<p class="help-block" ng-show="form.email.$error.mongoose">
{{ errors.email }}
</p>
</div>
</md-input-container>
</div>
<br /><br />
<div ng-show="form.email.$dirty && form.email.$valid">
<h5>Assign one of the following role's:</h5>
<div id="wrapperRadioButtons">
<md-radio-group ng-model="user.role">
<md-radio-button ng-repeat="userrole in roleInfo" value="{{userrole.id}}" class="md-primary">{{userrole.role}}</md-radio-button>
</md-radio-group>
</div>
</div>
<br />
</div>
</md-dialog-content>
<div class="md-actions" layout="row" >
<md-button ng-click="closeDialog()" class="md-primary">Cancel</md-button>
<md-button id="send_email" ng-click="inviteUser(); closeDialog()" class="md-primary">Invite</md-button>
</div>
</form>
</md-dialog>