I have been working on an angularjs webapp using WS of moodle to get information, I have a little problem with variables, I would like to get a variable from a $http. and I saw that you can use services as an option or $rootscope, but for me have not worked it.
I have two controller and i would like to pass $scope.userid to cursostCtrl
app.controller('userCtrl', function ($scope, $http) {
field = '&field=username';
values = '&values[0]=adminaccap'/*+$scope.username*/;
url = concatUrl + 'core_user_get_users_by_field' + field + values;
$http.get(url).then(function (response) {
$scope.items = response.data;
$scope.userid = response.data[0].id;
})
return $scope.userid;
});
app.controller('cursostCtrl', function($scope, $http){
url2 = concatUrl + 'core_enrol_get_users_courses' + '&userid=' + $scope.userid;
$http.get(url2).then(function (response) {
$scope.cursos = response.data;
$scope.nombrecurso = response.data[0].fullname;
})
Thanks for your help!
$scope.userid