Мы довольно кровавые новички с JavaScript и AngularJS, но сценарии довольно просты. Мы хотим установить html-свойства, полученные из службы REST.AngularJS set html properties
Это наш profileController.js:
angular
.module('app')
.controller('profileController', ['$scope', '$http', '$window', function($scope, $http) {
// REST service works properly
var resource = 'http://localhost:8080/user';
$http.get(resource).then(function(result){
// logs right json
console.log(result);
// no effect
$scope.content = result.data.toString();
// no effect
if(!$scope.$$phase) {
$scope.$apply();
}
});
} ]);
profile.html
<div>
<div class="container">
<br><br><br>
<h2 class="sub-header">Profile</h2>
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>#</th>
<th>Forename</th>
<th>Name</th>
<th>Role</th>
<th>E-Mail</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{profile.data}}</td>
<!-- Doesn't work as well
<td>{{profile.forename}}</td>
<td>{{profile.lastname}}</td>
<td>{{profile.role}}</td>
<td>{{profile.email}}</td>-->
</tr>
<div id="container" ng-controller="profileController">
<content-item forename="item"></content-item>
</div>
</tbody>
</table>
</div>
</div>
</div>
остального сервис работает правильно и отправляет обратно JSON, бревенчатые выходы в консоли JavaScript прав, просто настройка в html не работает, и у нас нет абсолютно никакой подсказки.
Заранее благодарен!
Почему '.ToString()', если вы получаете список пользователей? – Spikee
+1, toString() просто не должно быть здесь, вы больше не манипулируете json-объектом после этой строки. –
Это была просто демонстрация, что ничего не работает: $ scope.content = result.data; $ scope.forename = 'hallo'; this.lastname = 'lastname'; – Rooky