
Getting started
Dependencies
This repository contains a set of native AngularJS directives based on Foundation's markup and CSS. As a result no dependency on jQuery or Foundation's JavaScript is required. The only required dependencies are:
- AngularJS 1.5 (tested with 1.5.0)
- Foundation 6 CSS (tested with version 6.2.0).
Downloading
Build files for all directives are distributed in several flavours: minified for production usage, un-minified for development, with or without templates. All the options are described and can be downloaded from here.
Installation
As soon as you've got all the files downloaded and included in your page you just need to declare
a dependency on the mm.foundation
module:
angular.module('myModule', ['mm.foundation']);
You can fork one of the plunkers from this page to see a working example of what is described here.
Accordion (mm.foundation.accordion)
The body of the accordion group grows to fit the contents
<div ng-controller="AccordionDemoCtrl">
<label class="checkbox">
<input type="checkbox" ng-model="oneAtATime">
Open only one at a time
</label>
<accordion close-others="oneAtATime">
<accordion-group heading="Static Header, initially expanded" is-open="true">
This content is straight in the template.
</accordion-group>
<accordion-group heading="{{group.title}}" ng-repeat="group in groups">
{{group.content}}
</accordion-group>
<accordion-group heading="Dynamic Body Content">
<p>The body of the accordion group grows to fit the contents</p>
<button class="button small" ng-click="addItem()">Add Item</button>
<div ng-repeat="item in items">{{item}}</div>
</accordion-group>
<accordion-group is-open="isopen">
<accordion-heading>
I can have markup, too!
</accordion-heading>
This is just some content to illustrate fancy headings.
</accordion-group>
</accordion>
</div>
angular.module('foundationDemoApp').controller('AccordionDemoCtrl', function($scope) {
$scope.oneAtATime = true;
$scope.groups = [
{
title: "Dynamic Group Header - 1",
content: "Dynamic Group Body - 1"
},
{
title: "Dynamic Group Header - 2",
content: "Dynamic Group Body - 2"
}
];
$scope.items = ['Item 1', 'Item 2', 'Item 3'];
$scope.addItem = function() {
var newItemNo = $scope.items.length + 1;
$scope.items.push('Item ' + newItemNo);
};
});
Alert (mm.foundation.alert)
<div ng-controller="AlertDemoCtrl">
<alert ng-repeat="alert in alerts" type="alert.type" close="closeAlert($index)">{{alert.msg}}</alert>
<button class='button' ng-click="addAlert()">Add Alert</button>
</div>
angular.module('foundationDemoApp').controller('AlertDemoCtrl', function($scope) {
$scope.alerts = [
{ type: 'alert', msg: 'Oh snap! Change a few things up and try submitting again.' },
{ type: 'success round', msg: 'Well done! You successfully read this important alert message.' }
];
$scope.addAlert = function() {
$scope.alerts.push({type: 'alert', msg: "Another alert!"});
};
$scope.closeAlert = function(index) {
$scope.alerts.splice(index, 1);
};
});
Buttons (mm.foundation.buttons)
Single toggle
{{singleModel}}
Checkbox
{{checkModel}}
Radio
{{radioModel}}
<div ng-controller="ButtonsCtrl">
<h4>Single toggle</h4>
<pre>{{singleModel}}</pre>
<button type="button" class="button" ng-model="singleModel" btn-checkbox btn-checkbox-true="1" btn-checkbox-false="0">
Single Toggle
</button>
<h4>Checkbox</h4>
<pre>{{checkModel}}</pre>
<div class="button-group">
<button type="button" class="button" ng-model="checkModel.left" btn-checkbox>Left</button>
<button type="button" class="button" ng-model="checkModel.middle" btn-checkbox>Middle</button>
<button type="button" class="button" ng-model="checkModel.right" btn-checkbox>Right</button>
</div>
<h4>Radio</h4>
<pre>{{radioModel}}</pre>
<div class="button-group">
<button type="button" class="button" ng-model="radioModel" btn-radio="'Left'">Left</button>
<button type="button" class="button" ng-model="radioModel" btn-radio="'Middle'">Middle</button>
<button type="button" class="button" ng-model="radioModel" btn-radio="'Right'">Right</button>
</div>
</div>
angular.module('foundationDemoApp').controller('ButtonsCtrl', function ($scope) {
$scope.singleModel = 1;
$scope.radioModel = 'Middle';
$scope.checkModel = {
left: false,
middle: true,
right: false
};
});
Dropdown Toggle (mm.foundation.dropdownToggle)
<div ng-controller="DropdownCtrl">
<dropdown-toggle style="display: block;">
<toggle><a>Click me for a dropdown-toggle, yo!</a></toggle>
<pane>
<ul class="f-dropdown-toggle">
<li ng-repeat="choice in items">
<a>{{choice}}</a>
</li>
</ul>
</pane>
</dropdown-toggle>
<dropdown-toggle style="display: block;">
<toggle><a>dropdown-toggles can also have links!</a></toggle>
<pane>
<ul>
<li ng-repeat="(label, url) in linkItems">
<a href="{{url}}" target="_blank">{{label}}</a>
</li>
</ul>
</pane>
</dropdown-toggle>
<dropdown-toggle>
<toggle>
<a class="button split">
Split Button
<span dropdown-toggle-toggle="#dropdown-toggle-example-3"></span>
</a>
</toggle>
<pane>
<ul>
<li ng-repeat="choice in items">
<a>{{choice}}</a>
</li>
</ul>
</pane>
</dropdown-toggle>
</div>
angular.module('foundationDemoApp').controller('DropdownCtrl', function($scope) {
$scope.items = [
"The first choice!",
"And another choice for you.",
"but wait! A third!"
];
$scope.linkItems = {
"Google": "http://google.com",
"AltaVista": "http://altavista.com"
};
});
Modal (mm.foundation.modal)
<div ng-controller="ModalDemoCtrl">
<script type="text/ng-template" id="myModalContent.html">
<h3>I'm a modal!</h3>
<ul>
<li ng-repeat="item in items">
<a ng-click="selected.item = item">{{ item }}</a>
</li>
</ul>
<p>Selected: <b>{{ selected.item }}</b></p>
<button class="button" ng-click="ok()">OK</button>
<button ng-click="cancel()" class="close-button" aria-label="Close reveal" type="button">
<span aria-hidden="true">×</span>
</button>
</script>
<button class="button" ng-click="open()">Open me!</button>
<div ng-show="selected">Selection from a modal: {{ selected }}</div>
</div>
angular.module('foundationDemoApp').controller('ModalDemoCtrl', function ($scope, $modal, $log) {
$scope.items = ['item1', 'item2', 'item3'];
// for(var i = 0; i < 40; i++){
// $scope.items.push('item ' + i);
// }
$scope.open = function () {
var modalInstance = $modal.open({
templateUrl: 'myModalContent.html',
controller: 'ModalInstanceCtrl',
resolve: {
items: function () {
return $scope.items;
}
}
});
modalInstance.result.then(function (selectedItem) {
$scope.selected = selectedItem;
}, function () {
$log.info('Modal dismissed at: ' + new Date());
});
};
});
// Please note that $modalInstance represents a modal window (instance) dependency.
// It is not the same as the $modal service used above.
angular.module('foundationDemoApp').controller('ModalInstanceCtrl', function ($scope, $modalInstance, items) {
$scope.items = items;
$scope.selected = {
item: $scope.items[0]
};
$scope.reposition = function () {
$modalInstance.reposition();
};
$scope.ok = function () {
$modalInstance.close($scope.selected.item);
};
$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};
});
Pagination (mm.foundation.pagination)
Default
The selected page no: {{currentPage}}
Pager
Limit the maximum visible buttons
Page: {{bigCurrentPage}} / {{numPages}}
<div ng-controller="PaginationDemoCtrl">
<h4>Default</h4>
<pagination total-items="totalItems" page="currentPage"></pagination>
<pagination boundary-links="true" total-items="totalItems" page="currentPage" class="pagination-sm" previous-text="‹" next-text="›" first-text="«" last-text="»"></pagination>
<pagination direction-links="false" boundary-links="true" total-items="totalItems" page="currentPage"></pagination>
<pagination direction-links="false" total-items="totalItems" page="currentPage" num-pages="smallnumPages"></pagination>
<pre>The selected page no: {{currentPage}}</pre>
<button class="button secondary" ng-click="setPage(3)">Set current page to: 3</button>
<hr />
<h4>Pager</h4>
<pager total-items="totalItems" page="currentPage"></pager>
<hr />
<h4>Limit the maximum visible buttons</h4>
<pagination total-items="bigTotalItems" page="bigCurrentPage" max-size="maxSize" class="pagination-sm" boundary-links="true"></pagination>
<pagination total-items="bigTotalItems" page="bigCurrentPage" max-size="maxSize" class="pagination-sm" boundary-links="true" rotate="false" num-pages="numPages"></pagination>
<pre>Page: {{bigCurrentPage}} / {{numPages}}</pre>
</div>
angular.module('foundationDemoApp').controller('PaginationDemoCtrl', function ($scope) {
$scope.totalItems = 64;
$scope.currentPage = 4;
$scope.maxSize = 5;
$scope.setPage = function (pageNo) {
$scope.currentPage = pageNo;
};
$scope.bigTotalItems = 175;
$scope.bigCurrentPage = 1;
});
Tabs (mm.foundation.tabs)
Select a tab by setting active binding to true:
<div ng-controller="TabsDemoCtrl">
<p>Select a tab by setting active binding to true:</p>
<p>
<button class="button small" ng-click="tabs[0].active = true">Select second tab</button>
<button class="button small" ng-click="tabs[1].active = true">Select third tab</button>
</p>
<hr />
<tabset>
<tab heading="Static title">Static content</tab>
<tab ng-repeat="tab in tabs" heading="{{tab.title}}" active="tab.active">
{{tab.content}}
</tab>
<tab select="alertMe()">
<tab-heading>
<i class="fa fa-bell"></i> Alert!
</tab-heading>
I've got an HTML heading, and a select callback. Pretty cool!
</tab>
</tabset>
<hr />
<tabset vertical="true" type="navType">
<tab heading="Vertical 1">Vertical content 1</tab>
<tab heading="Vertical 2">Vertical content 2</tab>
</tabset>
<hr />
</div>
angular.module('foundationDemoApp').controller('TabsDemoCtrl', function ($scope) {
$scope.tabs = [
{ title:"Dynamic Title 1", content:"Dynamic content 1" },
{ title:"Dynamic Title 2", content:"Dynamic content 2" }
];
$scope.alertMe = function() {
setTimeout(function() {
alert("You've selected the alert tab!");
});
};
});
Animations
Foundation includes animations in its JavaScript files but the components above don't use Foundation's JavaScript. You can use the official Angular module ngAnimate in your project or simple CSS animations like the example below.
.fade {
opacity: 0;
transition: opacity .15s linear;
}
.fade.in {
opacity: 1;
}
.reveal.fade {
transition: transform .3s ease-out;
transform: translate(0, -25%);
}
.reveal.in {
transform: translate(0, 0);
}
.reveal-bg.fade {
filter: alpha(opacity=0);
opacity: 0;
}
.reveal-bg.in {
filter: alpha(opacity=50);
opacity: .5;
}