Answer the question
In order to leave comments, you need to log in
How to insert a value into a div from an array in angular js?
The question is, the first time I encountered angular, I want to start studying, I looked at a couple of lessons on YouTube and decided to try it, and the question immediately arose of how to arrange the div id from what is in the Ajax array?
<script>
var app = angular.module('app',[]);
app.controller("profileCtrl", function(){
var req="https://api.vk.com/method/users.get?user_ids=1"
$.ajax({
url : req,
type : "GET",
dataType : "jsonp",
success : function(msg){
//console.log(msg.response[0]);
}
});
})
</script>
</head>
<body ng-app="app">
<div class="container">
<div class="profile" ng-controller="profileCtrl">
<div id="First_name"></div>
<div id="Last_name"></div>
<div id="City"></div>
<div id="Avatar"></div>
</div>
</div>
</body>
Answer the question
In order to leave comments, you need to log in
<script>
var app = angular.module('app',[]);
app.controller("profileCtrl", function(){
var req="https://api.vk.com/method/users.get?user_ids=1"
$.ajax({
url : req,
type : "GET",
dataType : "jsonp",
success : function(msg){
//console.log(msg.response[0]);
$scope.msg = msg.response[0]
}
});
})
</script>
"$.ajax({....." is this jQuery?
There is a $http module for requests in Angular - https://docs.angularjs.org/api/ng/service/$http
then after getting the data you put it in model type :
..... success(function (data) {
$scope.data_from_server = data;
});
</head>
<body ng-app="app">
<div class="container">
<div class="profile" ng-controller="profileCtrl">
<div id="First_name"> {{data_from_server.First_name}} </div>
<div id="Last_name"> {{data_from_server.Last_name}} </div>
..........
</div>
</div>
</body>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question