$uibModal doesn't show my UI in my angular webpack project - angularjs

I am calling below function on ng-click of a button.
vm.updateSourceAndVisibility = function(skus) {
$log.info("In updateSourceAndVisibility");
var modal = $uibModal.open({
animation: true,
template: require('./source-selection/source.selection.html'),
controller: require('./source-selection/source.selection.controller.js'),
controllerAs: 'sourceSelectCtrl',
backdrop : 'static',
size: 'md'
});
};
When I click that button, a modal comes up having just
/src/app/pages/src/source-selection/source.selection.html
But source.selection.html has this HTML,
<form name="sourceSelectForm" novalidate>
<!-- modal header -->
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close" ng-click="sourceSelectCtrl.close()"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Select Sources</h4>
</div>
<!-- modal body -->
<div class="modal-body">
<!-- Source information -->
<div class="row">
I want to put something here
</div>
</div>
<!-- modal footer -->
<div class="modal-footer">
<button type="button" class="btn btn-default" ng-click="sourceSelectCtrl.close()">Cancel</button>
<button type="submit" class="btn btn-primary" ng-click="sourceSelectCtrl.submit()">Select</button>
</div>
</form>
What did I do wrong?

Related

Modal window has large background

I am using the iu.bootstrap.modal popup window on one of my views. The modal windows displays correctly except that it looks like it is inside a larger white frame.
What is causing this white frame to appear behind my modal window?
Here is my view:
<button type="button" id="btnModal" name="modal1" ng-click="openModal()" class="btn btn-primary pull-right">Open Modal</button>
<!--Modal-->
<script type="text/ng-template" id="myModal.html">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title">{{title}}</h3>
</div>
<div class="modal-body">
<span id="error-message" class="text-danger" style="white-space:pre">{{message}}</span>
</div>
<div class="modal-footer">
<button id="btn-ok" class="btn btn-primary" type="button" ng-click="ok()">OK</button>
</div>
</div>
</script>
And my controller
$scope.openModal = function () {
var title = "Modal Title";
var message = "Modal Message";
var modalInstance = $uibModal.open ({
animation: true,
templateUrl: 'myModal.html',
size: 'sm',
controller: function ($scope) {
$scope.title = title;
$scope.message = message;
$scope.ok = function () { modalInstance.dismiss() };
}
});
};
What causes the window to appear behind the modal?
In ui.bootstrap documentation (https://angular-ui.github.io/bootstrap/#/modal)
<script type="text/ng-template" id="myModalContent.html">
<div class="modal-header">
<h3 class="modal-title" id="modal-title">I'm a modal!</h3>
</div>
<div class="modal-body" id="modal-body">
<ul>
<li ng-repeat="item in $ctrl.items">
{{ item }}
</li>
</ul>
Selected: <b>{{ $ctrl.selected.item }}</b>
</div>
<div class="modal-footer">
<button class="btn btn-primary" type="button" ng-click="$ctrl.ok()">OK</button>
<button class="btn btn-warning" type="button" ng-click="$ctrl.cancel()">Cancel</button>
</div>
</script>
There is not a <div> of modal-content class. But you have at the beginning of the modal. The modal-content is a css Bootstrap class and it may cause the problem.

How can i create a ng-repeat Modal bootstrap with angular

So I have the following simple JSON in my controller:
var app = angular.module('MyApp', []);
app.controller('loadCtrl', function($scope,$http) {
$scope.buttons=[
{Id:'1', type:'First Button'
},
{Id:'2', type:'2nd Button'
},
{Id:'3', type:'3rd Button'
}
];
});
In my view, I have buttons generated by ng-repeat, and modals attached to each button:
<div ng-app="MyApp" ng-controller="loadCtrl" class="container">
<div ng-repeat="button in buttons" class="btn-group">
<div class="btn btn-sq-lg btn-primary" data-toggle="modal" ng-attr-data-target="{{button.type+'Opts'}}">{{button.type}}
</div>
<!-- Modal -->
<div ng-attr-id="{{button.type+'Opts'}}" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">{{button.type}}</h4>
<h5> Record:{{date | date:'yyyy-MM-dd-HH:mm:ss'}}</h5>
</div>
<div class="modal-body">
<textarea name="Reason" class="form-control" rows="5" style="min-width: 100%"></textarea>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
But for some reason, the modal just does not show up. I tried adding ng-show attribute, but that didn't work either. Somehow the ids aren't being generated properly.
You need to include the id selector '#' in data-target attribute, also for the selector to work button type needs no space.
<div ng-app="MyApp" ng-controller="loadCtrl" class="container">
<div ng-repeat="button in buttons" class="btn-group">
<div class="btn btn-sq-lg btn-primary" data-toggle="modal" data-target="{{'#' + button.type+'Opts'}}">{{button.type}}
</div>
<!-- Modal -->
<div id="{{button.type+'Opts'}}" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">{{button.type}}</h4>
<h5> Record:{{date | date:'yyyy-MM-dd-HH:mm:ss'}}</h5>
</div>
<div class="modal-body">
<textarea name="Reason" class="form-control" rows="5" style="min-width: 100%"></textarea>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
Controller :
var app = angular.module('MyApp', []);
app.controller('loadCtrl', ['$scope', '$http', function($scope, $http) {
$scope.buttons = [{
Id: '1',
type: 'FirstButton'
}, {
Id: '2',
type: '2ndButton'
}, {
Id: '3',
type: '3rdButton'
}];
}]);
See working demo here

Angular Bootstrap multiple modal backdrops

I'm using this modal service to show a basic dialog in an Angular app.
The implementation is simple but there are two issues:
The dialog shows but the modal-backdrop class is repeated multiple times, rendering it completely black.
When closing the dialog, the form closes but the background remains, leaving the view useless. I'm sure this is related to 1.
I'm using Angular 1.4.9 with angular-ui-bootstrap 0.13.4 [2015-09-03]. I've found a couple of posts showing incompatibilities between angular 1.4 and angular-ui-bootstrap but I've not managed to solve this.
Edit - view and controller code:
<button type="button" class="btn btn-sm btn-white" ng-click="procFileCtrl.viewErrors(file)"> <i class="fa fa-eye"></i> </button>
this.viewErrors = function(file) {
ModalService.showModal({
templateUrl: 'modules/components/client/modal/modal-base.html',
controller: 'FileController',
controllerAs: 'fileCtrl',
inputs: {
data: file
}
}).then(function(modal) {
modal.element.modal();
modal.close.then(function(result) {
this.message = result ? 'ok' : 'notok';
});
}).catch(function(error) {
console.log(error);
});
};
modal-base.html
<div class="modal inmodal in" id="myModal" tabindex="-1" role="dialog" aria-hidden="true" style="display: block;">
<div class="modal-dialog">
<div class="modal-content animated bounceInRight">
<div class="modal-header">
<!-- header here -->
</div>
<div class="modal-body">
<!-- body here -->
</div>
<div class="modal-footer">
<button type="button" class="btn btn-white" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>

Reset the values on Modal box on reload

Reset the values on Modal box on reload
<div class="modal fade" id="detailsModal" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header custom-modal-header">
<button type="button" class="close" data-dismiss="modal">
<span aria-hidden="true">×</span>
<span class="sr-only">Close</span>
</button>
<h4 class="modal-title" id="myModalLabel">
Create Job Vaccination
</h4>
</div>
<!-- Modal Body -->
<form name="vaccjobctrl.vaccineForm" class="form-inline" >
<div class="modal-body" style="height: 150px">
<div class="row ">
<div class="form-group col-md-12" ng-class="{ 'has-error' : vaccjobctrl.vaccineForm.screeningType.$invalid && (vaccjobctrl.vaccineForm.screeningType.$dirty || vaccjobctrl.vaccineForm.screeningType.$touched) }">
<label for="regId" class="col-md-6">Screening Type:</label>
<span class="col-md-6">
<select style="width: 100%;"
ng-model="vaccjobctrl.vaccineForm.screeningTypeMast.screeningTypeId"
ng-options="sctype.screeningTypeId as sctype.screeningType for sctype in vaccjobctrl.screeningTypeList"
class="form-control field-size ng-pristine ng-invalid ng-invalid-required ng-valid-maxlength ng-touched" name="screeningType"
id="screeningType" required>
<option value="">--SELECT--</option>
<option value="{{sctype.screeningTypeId}}">{{sctype.screeningType}}</option>
</select>
</span>
<div class="col-sm-6 error-color"
ng-if="vaccjobctrl.interacted(vaccjobctrl.vaccineForm.screeningType)"
ng-messages="vaccjobctrl.vaccineForm.screeningType.$error">
<div ng-messages-include="src/common/validation-messages.html"></div>
</div>
</div>
</div>
<!-- Modal Footer -->
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">
Cancel
</button>
<button type="button" class="btn btn-primary-joli" ng-click="vaccjobctrl.saveJobVaccination(vaccjobctrl.vacc);" ng-disabled="vaccjobctrl.vaccineForm.$invalid" data-dismiss="modal">
Create Vaccination
</button>
</div>
</form>
</div>
</div>
</div>
this is the modal box.
On click on open Modal this function will be called
vm.showModal = function() {
$('#detailsModal').modal('show');
};
values in the select box are pre-populated, on reopening the modal box it show the previously selected values. If trying to clear that the the select box border color changed to red on reopen.
In Bootstrap 3 you can reset your form after your modal window has been closed as follows:
$('.modal').on('hidden.bs.modal', function(){
$(this).find('form')[0].reset();
});
You can just reset any content manually when modal is hidden.
HTML:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
Launch modal
</button>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span>
</button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
<div class='modal-body1'>
<h3>Close and open, I will be gone!</h3>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
You can use:
$(".modal").on("hidden.bs.modal", function(){
$(".modal-body1").html("");
});
You can do more like:
$(document).ready(function() {
$(".modal").on("hidden.bs.modal", function() {
$(".modal-body1").html("Where did he go?!?!?!");
});
});
There are more about them in http://getbootstrap.com/javascript/#modals-usage.
UPDATE AS PER YOUR NEED:
If you want to do it angular way, use the jquery src above angularjs source in index.html. You can simply use the jquery functions inside the angularjs controller.
Working JsFiddle: http://jsfiddle.net/tnq86/15/
For using document.ready function in angular.
angular.module('MyApp', [])
.controller('MyCtrl', [function() {
angular.element(document).ready(function () {
document.getElementById('msg').innerHTML = 'Hello';
});
}]);
However Creating directive is the right way to do it. Follow the link to get some help with creating directive to execute jquery functions in angularjs.
jquery in angularjs using directive

AngularStrap - Popover in a Popover

I have a Angular Strap popover that contains form elements:
<button type="button" class="btn btn-success" bs-popover title="2nd popover" html="true" data-content="should become a form of some kind">
<span class='glyphicon glyphicon-plus'></span>
</button>
I load that into the first popover
<button type="button" "class="btn btn-default" bs-popover data-auto-close="1" data-html="true" data-content="{{popoverContent}}" data-animation="am-flip-x" title="1st popover">
Button label
</button>
using:
(function() {
"use strict";
angular.module("app").controller("managerController", ["$scope", "imageHierarchyRepository", "$templateCache", "$compile", function ($scope, imageHierarchyRepository, $templateCache, $compile) {
imageHierarchyRepository.query(function(data) {
$scope.hierarchies = data;
});
$scope.popoverContent = $templateCache.get("popoverTemplate.html");
};
}]);
})();
However the second popover doesn't show up, and I'm guessing that it has something to do with compiling the raw html string into the first popover. How do I correctly compile the contents of a popover in AngularJS?
I'm not sure if this will answer your question, but here's an example of how to show a popover within a popover using templates:
<button type="button" class="btn btn-primary" bs-popover data-title="primary popover" html="true" data-template-url="popoverTemplate.html">Primary popover</button>
<script type="text/ng-template" id="popoverTemplate.html">
<div class="popover" tabindex="-1">
<div class="arrow"></div>
<h3 class="popover-title" ng-bind="title" ng-show="title"></h3>
<div class="popover-content">
<button type="button" class="btn btn-default" bs-popover data-title="inner popover" html="true" data-template-url="popover2Template.html">
<span class="glyphicon glyphicon-plus"></span>
</button>
</div>
</div>
</script>
<script type="text/ng-template" id="popover2Template.html">
<div class="popover" tabindex="-1">
<div class="arrow"></div>
<h3 class="popover-title" ng-bind="title" ng-show="title"></h3>
<form class="popover-content">
<div class="form-group">
<label>Name:</label>
<input type="text" class="form-control"/>
</div>
</form>
</div>
</script>

Resources