AngularJS Material layout issue - angularjs

I've got a couple of layout issues with an Angular Material app. I'm quite new to AngularJS so hopefully it's just something obvious.
The first and most annoying is that I'm struggling with getting an Angular Material list looking as I'd like it to.
<md-content layout-padding>
<section>
<md-list ng-cloak>
<md-list-item class="md-3-line" ng-repeat="item in items | filter:filtered" go-click="item/{{item.id}}">
<md-icon class="material-icons">{{ item.acknowledgedBy ? 'assignment' : 'assessment'}}</md-icon>
<div class="md-list-item-text" layout="column" style="overflow: hidden; text-overflow: ellipsis;">
<h3>{{item.id}} - blah blah </h3>
<h4>2016-01-01 15:23:45</h4>
<h4>{{ item.description }}</h4>
</div>
<md-checkbox class="md-secondary" aria-label="Select {{item.id}}" ng-checked="selected.indexOf(item) > -1" ng-click="toggleSelection(item)"></md-checkbox>
</md-list-item>
</md-list>
</section>
</md-content>
The above worked as I expected until I added the checkbox to the list item. However this seems to prevent the text for the description being truncated with an ellipsis. Some of these descriptions can be large and I only want to show a lines worth, the primary action will show the info in full.
There is a plunker at https://plnkr.co/edit/thktG7C63cZv0FhqCzOD
My other niggle, on the same page is I'd like the both title bars to remain at the top of the page, the main app title and menu at the top and view specific title and menu options underneath. Currently the page specific one scolls up off the view.

Answer to your 2nd question.
Use md-content as the parent element since it will provide a scrollbar if needed.Now inside md-content whatever you place outside the 2nd md-content will not be scrollable and will work as a static header.
Here is a full code for that. I use simple ng-repeat and md-button to set more content and set header. You may use it as you like.
<md-content layout='column' layout-fill style='background-color:white'>
<md-toolbar class="md-whiteframe-glow-z1 site-content-toolbar">
<div class="md-toolbar-tools">
<md-menu>
<md-button aria-label="Menu" class="md-icon-button" ng-click="$mdOpenMenu($event)">
M
</md-button>
<md-menu-content width="4">
<md-menu-item>
<md-button go-click="/">
Home
</md-button>
</md-menu-item>
<md-menu-item>
<md-button go-click="/items">
Items (12)
</md-button>
</md-menu-item>
</md-menu-content>
</md-menu>
<h2>Mobile App</h2>
<span flex></span>
<md-button ng-click="page='report';option='option'">
Report Problem
</md-button>
<md-button ng-click="page='unread';option='unread option'">
Unread Messages
</md-button>
</div>
</md-toolbar>
<div layout='row'>
<span>
Current Page -> {{page}}
</span>
<span flex></span>
<span>
Options - {{option}}
</span>
</div>
<md-content flex layout='column' style='background-color:yellow'>
<md-button ng-repeat="item in [1,2,3,4,5,6,7,8,9,0]"> {{item}}</md-button>
<md-button ng-repeat="item in [1,2,3,4,5,6,7,8,9,0]"> {{item}}</md-button>
</md-content>
Here is a Working Example. http://codepen.io/next1/pen/yJyOvP

There are a few issues:
1. When screen is smaller than the line width of item.description things gets pushed out of the screen
This this caused by white-space: nowrap; on the <h4> tag. You can fix the layout by overriding it using white-space: normal;.
md-list-item.md-2-line .md-list-item-text h4, md-list-item.md-2-line > ._md-no-style .md-list-item-text h4, md-list-item.md-3-line .md-list-item-text h4, md-list-item.md-3-line > ._md-no-style .md-list-item-text h4 {
white-space: normal;
}
(I would actually use a <div> and give this a style instead of using <h4> tags because you get this kind of issues with most CSS frameworks.)
2. But now the text will wrap to the next line
I think it will be much easier to use the limitTo angular filter to do this with JavaScript than CSS. Set the value to something like 100, so it will show 100 characters of the string and hide the rest. Here's the original question: Limit the length of a string with AngularJS.
{{ "My String Is Too Long" | limitTo: 9 }} // outputs "My String"
3. Show both title bars
I think this is not possible unless you hack the Angular Material framework.

Related

md-tabs : unable to see pagination arrows when number of tabs exceeds

I am new to angularJS, I am trying md-tabs to create an items page, where each item is a tab on the page listing its details, here is my HTML code:
<md-content class="md-padding">
<md-tabs md-dynamic-height="" md-border-bottom="" md-autoselect="">
<md-tab ng-repeat="itemTab in itemList" label="{{itemTab.name}}">
<div style="padding: 35px; text-align: left;">
<div ng-repeat="detail in itemTab.details">
<p><pre>{{detail.info}}</pre></p>
</div>
</div>
</md-tab>
</md-tabs>
</md-content>
Here when the number of items increases, more than it can show on the page there is no pagination arrow that would help me to scroll to next set of items, can anyone help me with this problem?
The issue is probably related to you css. Try including the angular material css only and try if it works.

Vertical alignment of label followed by md-switch in angular material

I have a page in which a want to display some text in a label followed by a md-switch. I'm aware of the fact that I can remove the label completely and display the text after the switch, but this solution is not acceptable.
<md-content layout="row">
<label class="md-title">text</label>
<md-switch class="md-primary" ng-true-value="'YES'" ng-false-value="'NO'" ng-model="vm.data"> {{vm.data}}</md-switch>
</md-content>
I cannot seem to align these elements vertically. The switch is always lower than the text, not under the label, after it but much lower.
Some suggestions would be much appreciated.
You can add layout-align="start center" attribute or replace "start" with "center" or "end" if you want other alignment:
<md-content layout="row" layout-align="start center">
<label class="md-title">text</label>
<md-switch class="md-primary" ng-true-value="'YES'" ng-false-value="'NO'" ng-model="vm.data"> {{vm.data}}</md-switch>
</md-content>

Error Invalid HTML for md-menu: Expected two children elements

The expected behaviour of md-menu is that we do the following:
<md-menu>
<button ng-click="$mdOpenMenu()">Filters</button>
<md-menu-content>
<md-menu-item ng-repeat="field in devices.fieldList"><md-button ng-click="devices.setFilter(field)" ng-bind="field.name"></md-button></md-menu-item>
</md-menu-content>
</md-menu>
However I have a situation when using md-menu-bar that I want a quick access button to refresh some data, this causes an error Invalid HTML for md-menu: Expected two children elements. Although I could perhaps look at a different UI it feels like you should be able to have the following functionality wise it works great:
Snippet
<md-menu-bar>
<md-menu>
<button ng-click="$mdOpenMenu()">Filters</button>
<md-menu-content>
<md-menu-item ng-repeat="field in devices.fieldList"><md-button ng-click="devices.setFilter(field)" ng-bind="field.name"></md-button></md-menu-item>
</md-menu-content>
</md-menu>
<md-menu>
<button ng-click="data.refresh()"><md-icon class="material-icons">refresh</md-icon></button>
</md-menu>
</md-menu-bar>
Is there any reason this should not be done?
Every md-menu must specify exactly two child elements
https://material.angularjs.org/latest/api/directive/mdMenu
If you see your code, missing the second part of md-menu.
<md-menu>
<button ng-click="data.refresh()"><md-icon class="material-icons">refresh</md-icon></button>
</md-menu>
The second element is the md-menu-content element which represents the contents of the menu when it is open. Typically this will contain md-menu-items, but you can do custom content as well.
note: If you need a list of elements, try md-list:
<md-list>
<md-list-item>
<md-menu>
<button ng-click="$mdOpenMenu()">Filters</button>
<md-menu-content>
<md-menu-item ng-repeat="field in devices.fieldList"><md-button ng-click="devices.setFilter(field)" ng-bind="field.name"></md-button></md-menu-item>
</md-menu-content>
</md-menu>
</md-list-item>
<md-list-item>
<button ng-click="data.refresh()"><md-icon class="material-icons">refresh</md-icon></button>
</md-list-item>
</md-list>
for quick access button to refresh you can use it
<md-button ng-click="data.refresh()"><md-icon class="material-icons">refresh</md-icon></md-button>
check this link
if md-menu don't have children, use hide in md-menu-content to resolve the error
Home
<md-menu-content hide></md-menu-content>
</md-menu>

Angular JS Material mdMedia seems to be not working

I do have a toolbar
<md-toolbar layout="row">
<div class="md-toolbar-tools">
<md-button ng-click="mainCtrl.toggleSidenav('left')" ng-hide="$mdMedia('min-width: 16cm')"
class="md-icon-button">
<md-icon aria-label="Menu" md-svg-icon="https://s3-us-west-2.amazonaws.com/s.cdpn.io/68133/menu.svg">
</md-icon>
</md-button>
<h1>Test</h1>
</div>
The problem is with "'min-width: 16cm'"
I do have similar problems within a sidenav (with "ng-show="$mdMedia('max-width: 300px')") as well.
In the toolbar the button should vanish if the width is larger than 16cm. The button in the sidenav should only be visible if the with is smaller than 300.
The problem is the following: Either it is visible or not.
What am I doing wrong?
Thank you :)
Found it!
mdMedia was not referenced in the scope (Issue on Github).
So
$scope.$mdMedia = $mdMedia;
was all it needed ;)

How to put tool tip on the right when using <md-sidenav> using material?

I am using side navigation in my angular application, i am using buttons inside the side navigation with a tool tip on it. But it displays in bottom of the icon, i need it on the right side. I dont see any css attached to it.
Here is the code and plnkr:
<md-sidenav layout="column" class="md-sidenav-left md-whiteframe-z2" md-component-id="left" md-is-locked-open="$media('gt-sm')">
<md-list class="muppet-list">
<md-item ng-repeat="it in muppets">
<md-item-content>
<md-button ng-click="selectMuppet(it)" ng-class="{'selected' : it === selected }">
<img ng-src="{{it.iconurl}}" class="face" alt="">
{{it.name}}
</md-button>
<md-tooltip>
Create Chart
</md-tooltip>
</md-item-content>
</md-item>
</md-list>
</md-sidenav>
SIDE NAVIGATION
I have done it using the md-direction attribute
<md-tooltip md-direction="right">Save</md-tooltip>

Resources