所以我想在我的 Controller 中返回 bool 值。我唯一想做的就是尝试在 boolean 为 true
/false< 时将其与
隐藏普通用户不需要但仅适用于管理员的内容。这是我的代码:ng-show
/ng-hide
一起使用
我的adminController.js
的部分:
.constant("userUrl", "http://localhost:5500/users/type")
.controller("typeCtrl", function($scope, $http, userUrl) {
$http.get(userUrl, {withCredentials : true})
.success(function (data) {
$scope.users = data;
})
.error(function (error) {
$scope.error = error;
});
$scope.thisUser;
})
我的admin.html
的一部分我想使用该值,例如:
<div ng-show="thisUser == true" class="col-xs-3 panel-body">
希望你明白我的意思。
我从 Angular 开始,无法返回资源“users”中“type”的值以将其放入 Controller 的 View 中。
最佳答案
你必须做这样的事情:
$http.get(userUrl, {withCredentials : true})
.success(function (data) {
$scope.user = data;
})
<div ng-show="user.type == 'admin'" class="col-xs-3 panel-body">
关于javascript - 如何使用 $http.get 在 Controller 中返回 bool 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47655910/