0
ログインするユーザーがsendSMSプロパティーの値がtrueの場合にのみ、ボタンを表示したいとします。 htmlのng-showで何をすべきですか?また、プロパティの値を正しく配置すれば、私はあまり確信が持てません。私は基本モデルとしてUserを持つViewerモデルを作成し、このプロパティを使用してボタンを有効/無効にするためにsendSMSというプロパティを追加しました。プロパティ値のボタンベースの有効化/無効化
作成-サンプル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: 'User01', sendSMS: 'true'}
], cb);
});
}
};
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
};
});
}
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
};
}]);
- これは、サービスフォルダにある認証され
auth.js
angular
.module('app')
.controller('AuthLoginController', ['$scope', 'AuthService', '$state',
function($scope, AuthService, $state) {
$scope.Viewer = {
email: '',
password: '',
sendSMS: ''
};
$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');
});
};
}]);
- これは、コントローラのフォルダあなたがボタンの上にNG-disabledプロパティを使用することができます
report.htmlを
<button type="button" ng-show="currentUser.Viewer.sendSMS" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#myModal">
Send sms for selected </button>
report.htmlで 'currentUser.Viewer.sendSMS'値が正しく取得されているかどうか –