I have a service
.factory('myService', function($http, $q) {
var deffered = $q.defer();
var data = [];
var myService = {};
myService.async = function() {
$http.get('/*some json file from http adress*/')
.success(function (d) {
data = d;
deffered.resolve();
});
return deffered.promise;
};
myService.data = function() { return data; };
return myService;
});
and controller (for user state mainly)
.controller('Ctrl', function( myService, $scope) {
myService.async().then(function() {
$scope.dataarray = myService.data();
});
});
ui-router
.state('profile', {
url: '/user/:login',
templateUrl: 'userprofile.html',
controller: 'Ctrl',
})
and in user.html(the parent state of profile) I used (after ng-repeat user in dataarray )
ui-sref="profile({ login: user.login})
to go to my template for specific user page called userprofile.html
The final question is how get in userprofile.html whole date from json file connected to the specified user.login that I send through ui-sref to display eg. his name, avatar etc. from one json data entry. I think I have to use a some sort of new controller to use in profile state.
Aucun commentaire:
Enregistrer un commentaire