I want to show to the user a Yes/No dialog using AngularJS. If the user response is Yes, then I would like to call to another function of another controller and then load a new webpage.
So this is my controller with Angular-Material to show the dialog and it works:
var createDialogView = angular.module('CreateDialogView',['ngMaterial', 'ngMessages']);
createDialogView.controller('CreateDialogView', function($scope, $mdDialog) {
$scope.status = ' ';
$scope.customFullscreen = false;
$scope.ShowYesNoDialogView = function(ev, titleMsg, okMsg, cancelMsg) {
var confirm = $mdDialog.confirm()
.title(titleMsg)
.targetEvent(ev)
.ok(okMsg)
.cancel(cancelMsg);
$mdDialog.show(confirm).then(function() {
$scope.dialogYesNoUserResponse = //TODO;
}, function() {
$scope.dialogYesNoUserResponse = //TODO;
});
};
});
But I dont want to couple this controller to my business logic so I try to keep it reusable. I mean I dont want this controller to load a specific page, or call another specific controller of my app.
I want this controller to say the View using it that the user has choosen Yes or has choosen No. And then my view should perform some other action. In this case I want my View to call another controller function depending of the user response and finally load another view.
This is my view (this is part of a Single Page Application):
<div class="header-nightsky">
<nav class="navbar navbar-default">
<div class="container">
</div>
</nav>
<div class="hero" ng-controller="CreateDialogView" >
<h1>MyApp</h1>
<md-button class="btn btn-primary md-primary md-raised" ng-click="ShowYesNoDialogView($event, '¿Are you sure you want to leave?', 'Yes', 'No')">
Leave
</md-button>
</div>
</div>
Aucun commentaire:
Enregistrer un commentaire