I have an Angularjs controller(Angularjs 1.5.6) which calls a function from
a python script, which returns an array of elements. I am trying to do an
ng-repeat so that they appear in the table but for some reason, it doesn't
show the elements of the array.
The 'Go' button in the html template triggers the function getSID which
makes an HTTP call to a python script that returns an array. At the same
time, the function also sets the scope, showval to true such that the table
in the html appears only after the button is clicked.
<script>
angular.module('navigator', [])
.controller('HomeCtrl', function($scope, $http) {
$scope.getSid = function (sid) {
console.log(sid);
$http({
method: 'POST',
url: '/getMachine',
data: {sid:$scope.sid}
}).then(function(response) {
$scope.machines = [];
var object1 = response.data;
$scope.machines.push(object1);
//console.log(object1);
console.log($scope.machines);
$scope.showval = true;
}, function(error) {
console.log("hello");
console.log(error);
});
};
})
HTML CODE:
<div class="input-group mb-3 input-group-lg">
<div class="input-group-prepend">
<span class="input-group-text">Enter the SID</span>
</div>
<input type="text" class="form-control" ng-model="sid">
<button type="button" class="btn btn-outline-secondary"
ng-click="getSid(sid)" ng-model="show" >
GO!
</button></div><div ng-show="showval"><table class="table table-dark"
><thead><tr>
<th scope="col">SID</th>
<th scope="col">Cluster</th>
<th scope="col">Node</th>
<th scope="col">Physical ip</th>
<th scope="col">Logical ip</th>
<th scope="col">Logical Host</th>
<th scope="col">Physical Host</th></tr></thead><tbody><tr ng-repeat="item in
machines">
<td>{{item}}</td></tr>
</tbody></table></div>
I googled ng-repeat and so several examples in plunker and I am following the
same code but my code doesn't seem to work. Would be grateful for any
assistance. Thanks for your time.
--
You received this message because you are subscribed to the Google Groups
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.