I'm trying to pass index of object by clicking from one page to other but it's not working.
The page from index that need to be sent looks like this
<div><table>
<tr data-ng-repeat="profile in profiles">
<td>{{profile.profileName}}</td><td>{{profile.created}}</td>
<td>{{$index}}
<button data-ng-click="showUser($index)" type="button" class="btn btn-default btn-sm"><span class="glyphicon glyphicon-pencil"></span> Edit </button>
</table>
</div>
My app.js
looks like this
var app=angular.module('message',['restangular','ngRoute']);
app.config(['$routeProvider', function ($routeProvider){
$routeProvider
.when("/", {
templateUrl : "view/Home.html",
controller : "MainCtrl"
})
.when("/NewUser", {
templateUrl : "view/addUser.html",
controller : "MainCtrl"
})
.when("/ViewUsers", {
templateUrl : "view/ViewUsers.html",
controller : "MainCtrl"
})
.when("/EditUser", {
templateUrl : "view/EditUser.html",
controller : "MainCtrl"
});
}]);
app.controller('MainCtrl',function($scope,Restangular,$location){
Restangular.setBaseUrl('webapi');
var profiles = Restangular.all('profiles');
$scope.selected;
// This will query /profiles and return a promise.
profiles.getList().then(function(profiles) {
$scope.profiles = profiles;
$scope.saveUser=function(){
$scope.profile.profileName=$scope.profile.firstName+$scope.profile.lastName;
console.log($scope.profile);
profiles.post($scope.profile);
}
$scope.showUser=function(id){
console.log(id);
$scope.selected=id;
$scope.go('/EditUser');
}
$scope.editUser=function(id){
console.log(id);
var profile=$scope.profiles[id];
console.log(profile);
profile.put();
}
});
$scope.go = function ( path ) {
$location.path( path );
};
});
and page to which value need to be passed look like this
name:<input data-ng-model="profiles[id].profileName" type="text">
date:<input type="text" data-ng-model="profiles[id].created" readonly="readonly">
{{$scope.id}}
<button data-ng-click="editUser(id)">Edit User</button>
Can anyone give me some advice?