Я очень плохо знаком с angularjs и javascript.У меня есть такой рабочий код:
my_ctrl.js
app.controller('my_ctrl', function($scope, $filter, $http) {
$scope.getmymodel = function(){$http({
method: 'GET',
url: '/getmymodel',
headers: {'Content-Type': 'application/json'}
}).then(function(response){$scope.getmymodel=response.data;});};
$scope.getmymodel();
});
HTML:
<div ng-controller="my_ctrl as ctrl" ng-cloak>
<table class="table table-striped table-hover table-condensed">
<thead>
<tr>
<th>Name</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="model in getmymodel">
<td>{{model.name}}</td>
</tr>
</tbody>
</table>
</div>
Iхотел вызвать функцию js с помощью контроллера в HTML и сделать вызов функции локальным для контроллера.Я изменил код, как показано ниже, но не повезло.Любая помощь приветствуется!
my_ctrl.js
app.controller('my_ctrl', function($scope, $filter, $http) {
this.getmymodel = function(){$http({
method: 'GET',
url: '/getmymodel',
headers: {'Content-Type': 'application/json'}
}).then(function(response){this.getmymodel=response.data;});};
this.getmymodel();
});
HTML:
<div ng-controller="my_ctrl as ctrl" ng-cloak>
<table class="table table-striped table-hover table-condensed">
<thead>
<tr>
<th>Name</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="model in ctrl.getmymodel">
<td>{{model.name}}</td>
</tr>
</tbody>
</table>
</div>