How can I rotate image in AngularJs - angularjs

Here is my code: How can I rotate only the svg-arrow with angular on element box click ?
<md-card class="header" style="margin: 0 0 4px 0;" ng-mousedown="toggleCollapse('source')">
<md-card-content layout="row" layout-align="start center">
<img src="../assets/icons/cd-icon-arrow.svg" class="buildrag-toggle">
<h2 class="md-title no-top-margin no-bottom-margin" flex style="padding-left: 10px;">Data</h2>
<md-button class="md-icon-button header-button" ng-mousedown="addDataSource($event)">
<md-icon>add_circle_outline</md-icon>
</md-button>
</md-card-content>
</md-card>
Here is my button

Use ng-class to toggle a class when the button is clicked. Then use this class in css to rotate the image.
<md-card class="header" style="margin: 0 0 4px 0;" ng-mousedown="toggleCollapse('source')">
<md-card-content layout="row" layout-align="start center">
<img src="../assets/icons/cd-icon-arrow.svg" ng-class="{'rotate': rotateImg}" class="buildrag-toggle">
<h2 class="md-title no-top-margin no-bottom-margin" flex style="padding-left: 10px;">Data</h2>
<md-button class="md-icon-button header-button" ng-mousedown="addDataSource($event)" ng-click="rotateImg = !rotateImg">
<md-icon>add_circle_outline</md-icon>
</md-button>
</md-card-content>
</md-card>
.rotate {
-ms-transform: rotate(90deg); /* IE 9 */
-webkit-transform: rotate(90deg); /* Chrome, Safari, Opera */
transform: rotate(90deg);
}

When your button is clicked you handle it in the controller and add a class
Have a look at this
Controller :
$scope.todoClicked = function(id) {
console.log("clicked", id);
if (!$scope.showMoreTab[id]) {
$scope.showMoreTab[id] = true;
angular.forEach($scope.todos, function(todo) {
if (id !== todo.id) {
$scope.showMoreTab[todo.id] = false;
}
});
} else {
$scope.showMoreTab[id] = false;
}
}
View :
<md-button class="md-icon-button md-toggle-icon" aria-label="More" ng-click="todoClicked(todo.id)" ng-class="{'toggled':showMoreTab[todo.id]}">
<i class="material-icons">
keyboard_arrow_down</i>
</md-button>
CSS :
.md-toggle-icon.toggled {
-webkit-transform: rotate(180deg);
transform: rotate(180deg);
}
I am using a icon here but you can try it with svg as well.
<md-button class="md-icon-button md-toggle-icon" aria-label="More" ng-class="{'toggled':showMoreTab[todo.id]}" ng-click="todoClicked(todo.id)">
<md-icon md-svg-src="/material-design-icons/navigation/svg/design/ic_expand_more_36px.svg">
</md-icon>
</md-button>

Related

How to create a popup element to be over md-dialog?

I'm using AngularJs 1.7, and i've created a dropdown element that i want to add it to md-dialog, the problem is that my element (my-popup) always remains in the limits of the md-dialog - like in here
I want to achieve the same behaviour of the date-picker - as you can see - it's appears in the correct place and over the md-dialog - i wonder how it can done.
I've tried to append the popup to the body , but this way messed up the position of the popup - i guess there is a better way.
$scope.open = function(){
$scope.isShowMyPopUp = !$scope.isShowMyPopUp;
if(!!$scope.isShowMyPopUp){
let modalContainer = $('#myPopUp');
modalContainer.detach();
modalContainer.appendTo('body');
}
Here is the Example
You need to put your "myPopUp" div inside the dialog-content directly and modify your css like the following
HTML :
<md-dialog aria-label="Mango (Fruit)" class="mango-dialog">
<form ng-cloak>
<md-toolbar>
<div class="md-toolbar-tools">
<h2>Mango (Fruit)</h2>
<span flex></span>
<md-button class="md-icon-button" ng-click="cancel()">
<md-icon md-svg-src="img/icons/ic_close_24px.svg" aria-label="Close dialog"></md-icon>
</md-button>
</div>
</md-toolbar>
<md-dialog-content>
<div class="my-popup" ng-show="isShowMyPopUp" id-"myPopUp">
<div ng-repeat="item in daySelect">
<md-button class="md-raised md-primary" ng-class="{'selected':item.isSelected}" ng-click="select(item)"> {{item.text}}</md-button>
</div>
</div>
<div class="md-dialog-content">
<div layout-gt-xs="row">
<div flex-gt-xs>
<h4>Standard date-picker</h4>
<md-datepicker ng-model="ctrl.myDate" md-placeholder="Enter date"></md-datepicker>
</div>
<div flex-gt-xs style="position:relative;">
<h4>my-popup</h4>
<md-button class="md-raised md-primary" ng-click="open()">Open</md-button>
</div>
</div>
</div>
</md-dialog-content>
</form>
</md-dialog>
CSS :
.my-popup{
position:absolute;
top: 48px;
left: 104px;
width:250px;
height:250px;
background-color:gray;
z-index: 999;
overflow: auto;
}
md-dialog{
width:40%;
}
.selected {
background-color:green!important;
}
.mango-dialog {
overflow: visible;
}
I added mango-dialog class to your dialog to allow overflow , also I added z-index to the pop up to make sure it is on top
here is a working example

angular material right side bar issue

see this angular material demo at http://codepen.io/joyal/pen/mPpGBK
<div ng-controller="AppCtrl" layout="column" style="height:500px;" class="sidenavdemoBasicUsage" ng-app="MyApp">
<md-toolbar layout="column" class="main-toolbar md-medium-tall">
<span flex="flex">
<h1 class="md-toolbar-tools">Good luck overlapping me, sidenavs</h1>
</span>
</md-toolbar>
<section layout="row" flex="">
<md-sidenav class="md-sidenav-left md-whiteframe-z2" md-component-id="left" md-is-locked-open="$mdMedia('gt-md')">
<md-toolbar class="md-theme-indigo">
<h1 class="md-toolbar-tools">Sidenav Left</h1>
</md-toolbar>
<md-content layout-padding="" ng-controller="LeftCtrl">
<md-button ng-click="close()" class="md-primary" hide-gt-md="">
Close Sidenav Left
</md-button>
<p hide-md="" show-gt-md="">
This sidenav is locked open on your device. To go back to the default behavior, narrow your display.
</p>
</md-content>
</md-sidenav>
<md-content flex="" layout-padding="">
<div layout="column" layout-fill="" layout-align="top center">
<p>
The left sidenav will 'lock open' on a medium (>=960px wide) device.
</p>
<p>
The right sidenav will focus on a specific child element.
</p>
<div>
<md-button ng-click="toggleLeft()" class="md-primary" hide-gt-md="">
Toggle left
</md-button>
</div>
<div>
<md-button ng-click="toggleRight()" class="md-primary">
Toggle right
</md-button>
</div>
</div>
<div flex=""></div>
</md-content>
<div layout="row">
<!--This is new-->
<md-sidenav class="md-sidenav-right md-whiteframe-z2" md-component-id="right">
<md-toolbar class="md-theme-light">
<h1 class="md-toolbar-tools">Sidenav Right</h1>
</md-toolbar>
<md-content ng-controller="RightCtrl" layout-padding="">
<form>
<md-input-container>
<label for="testInput">Test input</label>
<input type="text" id="testInput" ng-model="data" md-sidenav-focus="">
</md-input-container>
</form>
<md-button ng-click="close()" class="md-primary">
Close Sidenav Right
</md-button>
</md-content>
</md-sidenav>
</div>
</section>
</div>
If you open the left side bar, it opens smoothly but if you open the right side bar, while opening and closing, a scroll bar appears on the page (horizontal scroll bar in the main content area).
How can I update the page so that right side bar opens and closes like left side bar (smoothly without scroll bar on content area)
You can use the overflow: hidden in your body, but it may effect to other component(s). Try this:
#sideNavContainer
{
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
overflow: hidden;
}
Hope this help.

AngularJS need to click more than 1 time for UI update?

I have simple button inside toolbar:
<md-toolbar>
<div class="md-toolbar-tools" layout="row" layout-align="space-between left">
<md-button class="md-icon-button" aria-label="Settings">
<md-icon md-svg-icon="images/ic_local_airport_24px.svg"></md-icon>
</md-button>
<h2>
<span class="md-title">
<font>
Title
</font>
</span>
</h2>
<span>
<!--
<md-button class="md-icon-button" aria-label="languageEnglish"
style='width: 1px !important;
padding-left: 2px !important;
padding-right: 2px !important;'>|</md-button>
-->
<md-button ng-click='test()' class="md-icon-button">Test</md-button>
</span>
</div>
</md-toolbar>
When I click the button, the function test() fires, but the ripple effect doesn't. I need to click it twice to ripple effect take place.
I also have tab:
<md-tabs class="tabs" layout="row" md-dynamic-height="" md-border-bottom=""
md-align-tabs="bottom" md-stretch-tabs="always" md-no-pagination="true" md-no-ink="false"
md-swipe-content="true">
<md-tab label="Home" ng-click="tab1Clicked()">
<md-tab-label>
<md-icon md-svg-icon="images/ic_local_airport_24px.svg"></md-icon>
<div class="tabsDivider"></div>
</md-tab-label>
</md-tab>
<md-tab label="Location" ng-click="tab2Clicked()">
<md-tab-label>
<md-icon md-svg-icon="images/ic_local_airport_24px.svg"></md-icon>
</md-tab-label>
</md-tab>
</md-tabs>
When I click the tab, it fires the function too but the tab UI is not updated. So for example, I am from tab1 clicks tab2, the tab2 background color is not updated although the logic inside the function has been executed. I need to click 2 times upto > 5 times (intermittently, sometimes 1 click also changes the UI).
Why does this happen? How to resolve it?

Angular material menu position (notification bar)

I'm trying to create a notification bar that shows up on the left bottom of the bell icon when it's clicked.
An example can be seen here : http://wrapbootstrap.com/preview/WB011H985
I tried giving it a specific margin-top (140px) but when you scroll down a little and clicked the bell, notification shows up way too below.
http://codepen.io/anon/pen/NxgePe
HTML
<div class="md-menu-demo menudemoMenuPositionModes" ng-controller="PositionDemoCtrl as ctrl" ng-cloak="" style="min-height:350px;" ng-app="MyApp">
<div class="menu-demo-container" layout-align="start center" layout="column">
<div class="menus" layout-wrap="" layout="row" layout-fill="" layout-align="space-between center" style="min-height:200px;">
<div layout="column" flex-sm="100" flex="33" layout-align="center center">
<p><code>md-position-mode="target-right target"</code></p>
<md-menu md-position-mode="">
<md-button aria-label="Open demo menu" class="md-icon-button" ng-click="$mdOpenMenu($event)">
<img ng-src="https://cdn4.iconfinder.com/data/icons/unigrid-flat-basic/90/019_025_bell_ring_alarm_notice_notification_notify-32.png">
</md-button>
<md-menu-content width="6">
<md-menu-item ng-repeat="item in [1, 2, 3]">
<md-button ng-click="ctrl.announceClick($index)">
<div layout="row">
<p flex="">Option {{item}}</p>
<md-icon md-svg-icon="call:portable-wifi-off" style="margin: auto 3px auto 0;"></md-icon>
</div>
</md-button>
</md-menu-item>
</md-menu-content>
</md-menu>
</div>
</div>
</div>
</div>
CSS
.menudemoMenuPositionModes .md-menu-demo {
padding: 24px; }
.menudemoMenuPositionModes .menu-demo-container {
min-height: 200px; }
#menu_container_0 {
background-color:red;
margin-top:140px;
}
JavaScript
angular
.module('MyApp',['ngMaterial', 'ngMessages'])
.config(function($mdIconProvider) {
$mdIconProvider
.iconSet("call", 'img/icons/sets/communication-icons.svg', 24)
.iconSet("social", 'img/icons/sets/social-icons.svg', 24);
})
.controller('PositionDemoCtrl', function DemoCtrl($mdDialog) {
var originatorEv;
this.openMenu = function($mdOpenMenu, ev) {
originatorEv = ev;
$mdOpenMenu(ev);
};
this.announceClick = function(index) {
$mdDialog.show(
$mdDialog.alert()
.title('You clicked!')
.textContent('You clicked the menu item at index ' + index)
.ok('Nice')
.targetEvent(originatorEv)
);
originatorEv = null;
};
});
Add an absolute positioning to the menu container...
In the case of your example, like this:
#menu_container_0 {
background-color:red;
position: absolute;
margin-top:140px;
}
http://codepen.io/anon/pen/VeWgvq

How to improve the sidenav animation performance angular material

I have made a sidenav using angular-material's md-sidenav and below is the screenshot of it. When i try click on the button for sidenav the animations pretty lagging. I have used on an image on the top bar and the rest just text with font-awesome icons. What could i be possibly doing bad that it is slow. The animations are even worse when i view it on mobile.
Screenshot of sidenav :
Here is the code of sidenav :
<md-sidenav class="boxme-sidenav" layout="column" hide-gt-sm class="md-sidenav-left md-whiteframe-z2" md-component-id="left">
<div layout="coloumn" style="z-index:1000;box-shadow:2px 0px 10px grey;">
<div flex class="sidenav-logo">
<img ng-src="{{mainLogo}}" alt="">
</div>
</div>
<md-list style="background-color:#00B0FF;color:white;z-index:10;">
<md-list-item class="md-2-line sidenav-list" layout-padding>
<md-button href="" layout-align="space-around center">
<i class="fa fa-size fa-briefcase"></i>
<span class="md-body-2">Dashboard</span>
</md-button>
</md-list-item>
<md-list-item class="md-2-line sidenav-list" layout-padding layout-align="start center">
<md-button href="">
<i class="fa fa-size fa-user"></i>
<span>My Stuff</span>
</md-button>
</md-list-item>
<md-list-item class="md-2-line sidenav-list" layout-padding layout-align="start center">
<md-button href="">
<i class="fa fa-size fa-file-o"></i>
<span>Order History</span>
</md-button>
</md-list-item>
<md-list-item class="md-2-line sidenav-list" layout-padding layout-align="start center">
<md-button href="">
<i class="fa fa-size fa-credit-card"></i>
<span>Billing</span>
</md-button>
</md-list-item>
<md-divider></md-divider>
<md-subheader style="background-color:#00B0FF;color:white;">Manage the items</md-subheader><!--You can use md-no-sticky class-->
<md-list-item class="md-2-line sidenav-list" layout-padding layout-align="start center">
<md-button href=""><i class="fa fa-size fa-user"></i> Pickup my stuff</md-button>
</md-list-item>
<md-list-item class="md-2-line sidenav-list" layout-padding layout-align="start center">
<md-button href=""><i class="fa fa-size fa-user"></i> Deliver my stuff</md-button>
</md-list-item>
</md-list>
</md-sidenav>
Note :
After a while the performance and animations of sidenav get real lagging on the web.
It may not be right solution for your case, but disabling backdrop and adding 1 tweak made transition performance acceptable for me (even on phone)
.md-sidenav-backdrop {
opacity: 0 !important;
}
md-sidenav.md-closed-add,
md-sidenav.md-closed-remove {
-webkit-transition: all .4s cubic-bezier(0.25, .8, .25, 1) !important;
transition: all .4s cubic-bezier(0.25, .8, .25, 1) !important;
}
I decided to just remove the animation as follows:
I looked through the AngularMaterial CSS file and removed all references to animations. KA-BOOM!
/**
* fix md-sidenav lag by removing animation
**/
.md-sidenav-backdrop {
opacity: 0 !important;
}
md-sidenav.md-closed-add,
md-sidenav.md-closed-remove,
md-sidenav.md-closed-add.md-closed-add-active,
md-sidenav.md-closed-remove.md-closed-remove-active,
md-sidenav.md-locked-open-remove-active,
md-sidenav.md-closed.md-locked-open-add-active
{
-webkit-transition: none !important;
transition: none !important;
}
---- edit ----
Also update to the latest version of AngularMaterial there seems to be an overall improvement in v1.0.0-rc4 compared to prior releases.

Resources