.controller('ProfileDetail', function($scope, $http) {
$scope.myFunc = function (id) {
// получаем json
$scope.url = 'profile/?=' + id;
$http.get($scope.url).success(function (data) {
return data;
}).error(function (data, status) {
$scope.response = 'Request failed';
});
};
});
<div ng-controller="ProfileDetail">
<div>
{{ myFunc(4) }}
/div>
</div>
angular.module('app')
.controller('ProfileDetail', $scope, $http) {
$scope.$watch('selectedId', function (id) {
if (!id) {
$scope.data = {};
return;
}
var url = 'profile/?=' + id;
$http.get(url).then(function (response) {
$scope.data = response.data;
}, function () {
// обрабатывайте ошибки
})
});
})
<div ng-controller="ProfileDetail">
<div>
{{ data }}
/div>
<span class="btn" ng-click="selectedId = 4"></span>
</div>
.controller('ProfileDetail', function($scope, $http) {
var url = 'profile/?=4';
$http.get(url).success(function (data) {
$scope.data = data;
}).error(function (data, status) {
$scope.response = 'Request failed';
});
});
<div ng-controller="ProfileDetail">
<div>
{{ data }}
/div>
</div>
.controller('ProfileDetail', function($scope, $http) {
$scope.data = '';
$scope.doThisShit = function(id){
var url = 'profile/?=' + id;
$http.get(url).success(function (data) {
$scope.data = data;
}).error(function (data, status) {
$scope.response = 'Request failed';
});
}
});
<div ng-controller="ProfileDetail">
<div ng-click="doThisShit(4)">
{{ data }}
/div>
</div>
$scope.myFunc = function(id) {
var result = 'loading...';
$scope.myFunc = function() { return result };
$http.get($scope.url).success(function (data) {
result = data;
})
return result
};