ログインするユーザーがsendSMSプロパティーの値が 'true'の場合にのみ、ボタンを表示します。ユーザーを基本モデルとするビューアモデルにプロパティを追加しました。 ng-show = "(Viewer.sendSMS == 'true')が必要な場合は、ボタンを表示できません。イム私の質問を明確にフレーズすることはできませんが、理解できることを願っています。コントローラで特定の値に従ってボタンを表示する
auth.jsサービスで
angular
.module('app')
.controller('AuthLoginController', ['$scope', 'AuthService', '$state',
function($scope, AuthService, $state) {
$scope.user = {
email: '',
password: ''
};
$scope.login = function() {
AuthService.login($scope.user.email, $scope.user.password)
.then(function() {
$state.go('report');
});
};
}])
.controller('AuthLogoutController', ['$scope', 'AuthService', '$state',
function($scope, AuthService, $state) {
AuthService.logout()
.then(function() {
$state.go('home');
});
}])
.controller('SignUpController', ['$scope', 'AuthService', '$state',
function($scope, AuthService, $state) {
$scope.user = {
email: '',
password: ''
};
$scope.register = function() {
AuthService.register($scope.user.email, $scope.user.password)
.then(function() {
$state.transitionTo('report');
});
};
}]);
auth.js
angular
.module('app')
.factory('AuthService', ['Viewer', '$q', '$rootScope', function(Viewer, $q,
$rootScope) {
function login(email, password, sendSMS) {
return Viewer
.login({email: email, password: password, sendSMS: sendSMS})
.$promise
.then(function(response) {
$rootScope.currentUser = {
id: response.user.id,
tokenId: response.id,
email: email,
sendSMS: sendSMS
};
});
}
function logout() {
return Viewer
.logout()
.$promise
.then(function() {
$rootScope.currentUser = null;
});
}
function register(email, password, sendSMS) {
return Viewer
.create({
email: email,
password: password,
sendSMS: sendSMS
})
.$promise;
}
return {
login: login,
logout: logout,
register: register
};
}]);
作成-サンプルmodel.js
var async = require('async');
module.exports = function(app) {
//data sources
var db = app.dataSources.db;
//create all models
async.parallel({
viewers: async.apply(createViewers),
}, function(err, results) {
if (err) throw err;
});
//create reviewers
function createViewers(cb) {
db.automigrate('Viewer', function(err) {
if (err) return cb(err);
var Viewer = app.models.Viewer;
Viewer.create([
{email: '[email protected]', password: 'example123', sendSMS: 'false'},
{email: '[email protected]', password: 'User0102', sendSMS: 'true'}
], cb);
});
}
};
report.htmlを
<button type="button" ng-show="(Viewer.sendSMS == 'true')" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#myModal">
- これは、sendSMSプロパティを使用して、ログインしているユーザーのプロパティに設定されている値に従ってボタンを有効にする場合です。