How to Angular Material datepicker leave/keep opened - angularjs

I've tried with md-blur md-focus, each fails. I'm using Angular Material 1.1.3 and i need to keep datepicker opened after date picked action. So, how to keep it opened, after this action. Anybody can help?

Due to the md-datepicker documentation you can't achieve this. ngMaterials is good but comes with a lot of limitations. You can 'fake' this by using md-calendar like in this runnable demo codepen.
View
<div ng-app="MyApp" ng-controller="MyController" layout-padding>
{{ date }}<br />
<input type="date" ng-model="date" ng-click="openDatePicker()" ng-show="!datePickerOpened">
<md-calendar class="fixed-calendar" ng-show="datePickerOpened" ng-model="date"></md-calendar>
</div>
CSS
.fixed-calendar {
width: 340px;
height: 340px;
display: block;
}
.fixed-calendar .md-calendar-scroll-mask {
width: 340px !important;
}
.fixed-calendar .md-virtual-repeat-scroller {
width: 340px !important;
height: 308px;
}
Application
angular
.module('MyApp', ['ngMaterial'])
.controller('MyController', function($scope, $timeout) {
//Init
$scope.datePickerOpened = false;
$scope.date = new Date();
//show datepicker action
$scope.openDatePicker = function () {
//show datepicker
$scope.datePickerOpened = true
//avoid date set to 1933 by async reinit date after ng-show rendering
$timeout(function () {
$scope.date = new Date();
});
}
});

Related

I have the following code for a popover however when I resize the page, i want to close the popover

My html
<div id="deviceInputContainer">
<div class="row noMarg">
<div class="form col-xs-12" style='padding-left:0px;margin-right:15px;'>
<div class="form col-xs-12 noPad left">
<h2 class="page-title">Certification Projects
<span class='icon-settings-big' style='cursor:pointer;float:right;margin-top:-10px;' title='settings' uib-popover-template="dynamicPopoverPageSettings.templateUrl"
popover-placement="bottom-right" popover-trigger="click outsideClick" popover-class="settingsClass" ></span>
</h2>
</div>
<div class="helpMessage" style="margin-left:-15px;margin-right:-15px;" ng-show="dashboardData.userPreferences.showHelpTextEnabled">
<p class="help-text-content col-sm-12 helpText-color helpText-size" style='margin-bottom:15px;'>Your open projects are listed below- but you can search for other projects if you want. Just
set the search criteria below.</p>
</div>
</div>
</div>
</div>
My controller code to toggle popover and on window resize close popover.
But popover hide is not working on window rezise, can somebody please help me where am i doing wrong
$scope.dynamicPopoverPageSettings = {
templateUrl: 'myPopoverTemplatePageSetting.html',
title: 'Page Settings',
isPopOpen: false,
setIsPopOpen: function() {
$scope.dynamicPopoverPageSettings.isPopOpen = !$scope.dynamicPopoverPageSettings.isPopOpen;
console.log("$scope.dynamicPopoverPageSettings.isPopOpen == " + $scope.dynamicPopoverPageSettings.isPopOpen);
},
setIsPopFalse: function() {
$scope.dynamicPopoverPageSettings.isPopOpen = false;
console.log("$scope.dynamicPopoverPageSettings.isPopOpen == " + $scope.dynamicPopoverPageSettings.isPopOpen);
}
};
var w = angular.element($window);
w.bind('resize', function () {
$('.settingsClass ').popover('hide');
});
When using angular if not using it already id recommend using Angular-Bootstrap-native AngularJS directives based on Bootstrap's markup and CSS. I've included this link to their site, it's the 0.14.3 docs. Also including this Codepen with an example of what I think you're trying to accomplish. Hope it helps, I can always help and modify it further.
function exampleController($scope, $window) {
$scope.popoverVisible = false;
function onResize() {
$scope.popoverVisible = false;
// manuall $digest required as resize event
// is outside of angular
$scope.$digest();
}
function cleanUp() {
angular.element($window).off("resize", onResize);
}
angular.element($window).on("resize", onResize);
$scope.$on("$destroy", cleanUp);
}
angular
.module("example", ["ui.bootstrap"])
.controller("exampleController", exampleController);
html,
.container,
.container-fluid {
width: 100%;
height: 100%;
background-color: #333;
color: #fff;
text-align: center;
button {
margin-top: 10%;
font-weight: bold;
}
button:focus {
outline: 0;
}
.popover {
.popover-title,
.popover-content {
color: #333;
}
}
}
<div class="container-fluid" ng-app="example">
<div class="container" ng-controller="exampleController">
<button uib-popover="I have a title!" popover-title="The title." popover-placement="bottom-right" popover-is-open="popoverVisible" type="button" class="btn btn-primary">
CLICK ME
</button>
</div>
</div>

using ng-change on datepicker angularjs

i am creating a web app in which i want to show the date in console on ng-change of my datepicker textbox
here is my code
<div class="form-group">
<h3>Enter Date</h3>
<div id="datepicker" class="input-group date" data-date-format="dd-mm-yyyy">
<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
<input class="form-control" ng-model="mddate" ng-blur="chngDate(mddate)" type="text" readonly />
</div>
<style>
label {
margin-left: 20px;
}
#datepicker {
width: 180px;
margin: 0 20px 20px 20px;
}
#datepicker > span:hover {
cursor: pointer;
}
</style>
<script>
$(function () {
$("#datepicker").datepicker({
autoclose: true,
todayHighlight: true
}).datepicker('update', new Date());;
});
</script>
</div>
but the problem is ng-change is not working with bootstrap datepicker,
here is my function inside controller
$scope.chngDate = function (date) {
var dates = new Date();
console.log(dates);
}
and i tried to use $watch function on the particular textbox but this is not working either
$scope.$watch('mddate', function (newValue, oldValue) {
console.log('oldValue=' + oldValue);
console.log('newValue=' + newValue);
//do something
});
this is showing undefined value at first then the function is not executing
what i need to do?
use ng-blur instead of ng-change, its working for me

Angular JS expression not evaluating

I have written a simple Angular JS code. I'm a beginner. However, one of my expressions is not getting evaluated. Need help. Please check the code below -
var myAppModule = angular.module('myAppModule', []);
myAppModule.controller('myController', function($scope){
// Hide colors by default
$scope.isHidden = true;
// a function, placed into the scope, which
// can toggle the value of the isHidden variable
$scope.showHideColors = function () {
$scope.isHidden = !$scope.isHidden;
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<!DOCTYPE html>
<html ng-app="myAppModule">
<head>
<title>Angular JS</title>
<script src="js/angular.min.js"></script>
<script src="js/myAppModule.js"></script>
<style>
body {
font-family: "Lucida Grande", "Lucida Sans Unicode", Helvetica, Arial, sans-serif;
}
div {
margin: 20px;
padding: 20px;
font-size: 16px;
color:#ffffff;
}
#red {
background-color: red;
}
#green {
background-color: green;
}
#blue {
background-color: blue;
}
#purple {
background-color: purple;
}
#gray {
background-color: gray;
}
#olive {
background-color: olive;
}
</style>
</head>
<body ng-controller="myController">
<h2>AngularJS Socks</h2>
<p>Keep warm this winter with our 100% wool, 100% cool, AngularJS socks!</p>
<button ng-click="showHideColors()" type="button">
{{isHidden ? 'Show Available Colors' : 'Hide Available Colors'}}
</button>
<div id="red" ng-hide="isHidden">Red</div>
<div id="green" ng-hide="isHidden">Green</div>
<div id="blue" ng-hide="isHidden">Blue</div>
<div id="purple" ng-hide="isHidden">Purple</div>
<div id="gray" ng-hide="isHidden">Dark Slate Gray</div>
<div id="olive" ng-hide="isHidden">Olive</div>
</body>
</html>
The expression - {{isHidden ? 'Show Available Colors' : 'Hide Available Colors'}} is not getting evaluated but displaying as is on the button. No clue as to what i missed. Thanks in advance.
The code is missing closing bracket. You can see the working demo here - http://jsfiddle.net/me8j3zyc/
var app = angular.module('myAppModule', []);
app.controller('myController', function($scope) {
$scope.isHidden = true;
// a function, placed into the scope, which
// can toggle the value of the isHidden variable
$scope.showHideColors = function() {
$scope.isHidden = !$scope.isHidden;
} // <- This is missing.
});
This is because you havent closed your function
myAppModule.controller('myController', function($scope){
// Hide colors by default
$scope.isHidden = true;
// a function, placed into the scope, which
// can toggle the value of the isHidden variable
$scope.showHideColors = function() {
$scope.isHidden = !$scope.isHidden;
}})
Your expression is fine, but you have a typo error in your JS file:
var myAppModule = angular.module('myAppModule', []);
myAppModule.controller('myController', function($scope) {
// Hide colors by default
$scope.isHidden = true;
// a function, placed into the scope, which
// can toggle the value of the isHidden variable
$scope.showHideColors = function() {
$scope.isHidden = !$scope.isHidden;
} //MISSING
});
You can try this:
<button ng-if="isHidden" ng-click="showHideColors()" type="button">Show Available Colors</button>
<button ng-if="!isHidden" ng-click="showHideColors()" type="button">Hide Available Colors</button>

ondrop ondragover - Uncaught ReferenceError: ondrop is not defined - angular - html5 draggable

I try to implement html5 drag and drop with angular.
The code is:
<div ondrop="drop(event)"></div>
And in the controller:
$scope.drop = function(e) { console.log('a drop') };
This leads to the error:
Uncaught ReferenceError: drop is not defined
Exchanging 'ondrop' with 'ng-click' makes it work, so there is nothing missing in the controller.
ondrop is a HTML attribute, therefore it expects the given function to be global, as opposed to angular directives such as ng-click which expect the callbacks to be published on the $scope.
You can use non angular events by connecting functions, that fire in that events to your scope. In this case:
ondrop='angular.element(document.getElementById("Id of element with ngController,or ngView(if you use router)")).scope().drop(event)'
Here I modified the drag and drop example from W3Schools:
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.6/angular.min.js"></script>
<style>
#div1, #div2 {
float: left;
width: 100px;
height: 35px;
margin: 10px;
padding: 10px;
border: 1px solid black;
}
</style>
<body ng-app="myApp">
<div data-ng-controller="myCtrl" id="myContrId">
<div id="div1" ondrop='angular.element(document.getElementById("myContrId")).scope().drop(event)' ondragover='angular.element(document.getElementById("myContrId")).scope().allowDrop(event)'>
<img src="https://diethelper.xyz/DHadmin/images/logo2w.png" draggable="true" ondragstart='angular.element(document.getElementById("myContrId")).scope().drag(event);' id="drag1" width="88" height="31">
</div>
<div id="div2" ondrop='angular.element(document.getElementById("myContrId")).scope().drop(event)' ondragover='angular.element(document.getElementById("myContrId")).scope().allowDrop(event)'></div>
</div>
<script>
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
$scope.allowDrop = function(ev) {
ev.preventDefault();
}
$scope.drag = function(ev) {
ev.dataTransfer.setData("text", ev.target.id);
}
$scope.drop = function(ev) {
ev.preventDefault();
var data = ev.dataTransfer.getData("text");
ev.target.appendChild(document.getElementById(data));
}
});
</script>
</body>
</html>
ng-click is a directive defined by angular itself. ondrop, is as far as I'm aware not part of angular's standard library. You will need to define a new directive in order to get the functionality you want. I would recommend checking out this blog post
http://blog.parkji.co.uk/2013/08/11/native-drag-and-drop-in-angularjs.html

how to auto scroll to a div in angular js

i want my error message div to appear when i click on the submit button and i want that screen should auto scroll to that div my code snippet are below:
CSS:-
.error_msg
{
background: none repeat scroll 0 0 #F16200;
border: 0 solid #FF1055;
color: #EFEFEF;
display: block;
margin-top: 5px;
text-align: center;
width: 41%;
}
HTML of that div:
<div id="error" class="error_msg"> Speed Link Successfuly Created for {{display}}
controller which is invoking on submit:-
tmeModuleApp.controller('speedLinksController',function($scope,APIServices,Paths,$rootScope) {
$scope.setSpeedLink =function() {
var setLink = $('.active').attr('valset_link');
var display = $('.active').attr('valset_display');
var display_name = $('.active').attr('valset_link_name');
if(setLink != '')
{
$location.hash('error');
$scope.display= display_name;
}
}
}
Check out angulars $anchorScroll service.
You should inject $anchorScroll and call it after $locaiton.hash call.
Update
Example
HTML
<div id="scrollArea" ng-controller="ScrollCtrl">
<a ng-click="gotoBottom()">Go to bottom</a>
<a id="bottom"></a> You're at the bottom!
</div>
JS
function ScrollCtrl($scope, $location, $anchorScroll) {
$scope.gotoBottom = function (){
// set the location.hash to the id of
// the element you wish to scroll to.
$location.hash('bottom');
// call $anchorScroll()
$anchorScroll();
};
}

Resources