I had this problem for AngularJS UI. I created a service to fetch a get method api /member/item/ + id, where my parameter id is the specified userID in my database table. I already setup a controller but I keep getting an error. Somehow I manage to get the ID of the user when I declare the value as 1. But I tried to make it dynamic it gives me error.
Controller
app.controller('mainCtrl', function($scope, $window, $rootScope, adminService){
$scope.usertype = localStorage.usertype;
$rootScope.usertype = localStorage.usertype;
$rootScope.userID = localStorage.userID;
$scope.username = localStorage.username;
// $scope.userID = 1;
$scope.id= $scope.userID;
// $scope.userID = localStorage.userID;
adminService.editMember($scope.id)
.then(function(data){
//array
$scope.id = data.data[0].userID;
$scope.f_name = data.data[0].first_name;
$scope.email = data.data[0].email;
});
});
Service
function editMember(id) {
return $http({
method: 'get',
url: rootURL + '/member/item/' + id,
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
})
}
MemberInfo.html
<div class="card-body">
<h6 class="card-title mb-1 large">
<a href="#" class="col-xs-10" >
<h4>FirstName: , </h4>
<label >ID: </label>
</a>
<label class="btn btn-primary pull-right" name="editInfo"><input type="checkbox" class="hidden" for="editInfo" name="editInfo" ng-model="editInfo"> <ic class="fa fa-pencil"></i></label>
<form name="myForm" ng-submit="saveProfile()">
<label></label>
<div class="form-group">
<div class="form-row">
<div class="col-md-6">
<label>Role : </label>
<input type="text" class="form-control" name="role" ng-model="usertype" readonly>
</div>
<div class="col-md-6">
<label>Email : </label>
<input type="email" class="form-control" name="email" ng-model="email" ng-readonly="!editInfo">
</div>
</div>
</div>
</form>
</div>
Source: AngularJS
from Angular Questions https://angularquestions.com/2017/10/01/angularjs-display-dynamic-id-and-info-of-particular-user-in-scope-when-login-with-service-and-api-to-fetch-in-mysql/
via @lzomedia #developer #freelance #web #lzomedia.com
No comments:
Post a Comment