0
My doubt is the following, Gero 6 determined panels in the script.js file that is with names defined as Paineis1, Paineis2... what would you like, do a get in a url, and for every url I call it add the answer inside the panel
I got the following index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="style.css" />
<script src="//code.angularjs.org/snapshot/angular.min.js"></script>
<script src="script.js"></script>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div ng-app="myApp">
<div ng-controller='myController'>
<div class='painel' ng-repeat='i in paineis'>{{i}}</div>
</div>
</div>
</body>
</html>
js scripts.:
angular.module('myApp', [])
.controller('myController', function($scope){
$scope.paineis = ['Painel1','Painel2','Painel3','Painel4','Painel5','Painel6'];
});
Sponse.js:
angular.module('myApp', [])
.controller('myCtrl', function($scope, $http) {
$http.get("http://jsonplaceholder.typicode.com/posts/1/commentsssss")
.then(function(response) {
$scope.content = response.status;
}, function(response) {
$scope.content = response.status;
});
});
When do you want to execute the request? As soon as the page loads? What is the file
response.js? The controllermyCtrlis what should be responsible for handling the requisitions?– Woss
as soon as the page loads would be desirable, I believe yes, I am beginner, I do not know if this was the best way to separate the controllers
– Guilherme Lima
It’s been a while since I’ve worked with Angular, but I don’t think I should create another controller for this. You can define the function within the
myController. The requested URL for each panel will be the same?– Woss
no, I intend to change this url according to the panel numbers
– Guilherme Lima
Using Angular version 1, correct? Directive does not solve your problem?
– Woss