On Github aeharding / ngGrid-madJs-talk
By Alexander Harding | http://github.com/aeharding
(It's just that Angular data grids are a good example)
I'm biased. I use smart-table 1.x in my day job [CUI].
But it took a while to get there...
...
(4. Comments)
Angular, like JS, has many ways to do the same thingWeb Component-y
Less obfuscated HTML w/ div, span
Transclusion
Cannot use w/ native HTML element
Multiple directive elements on same element...
'value'... <div my-directive="val">
Multiple directives on one element
... And more, that I will get to
More obfuscated DOM -- need 'filler' div, span
Will not talk about class, commentindex.html:
<my-wicked-button></my-wicked-button>
my-wicked-button.partial.html:
<button ng-transclude class="my-wicked-button"></button>
my-wicked-button.js:
angular.module('app').directive('myWickedButton', function() {
return {
restrict: 'E',
transclude: true,
templateUrl: 'my-wicked-button.partial.html',
scope: {},
link: function(scope, element, attrs) {
console.log('intialized My WICKED BUTTON!!');
}
}
});
This works great.
For a button.
<my-wicked-button hint="A hint when you hover"> <i class="fa fa-flag"></i> BOOM </my-wicked-button>
<my-wicked-button hint="<i class="fa fa-flag"></i> A hint when you hover"> <i class="fa fa-flag"></i> BOOM </my-wicked-button>
<my-wicked-button hint="A hint when you hover" hint-icon="flag"> <i class="fa fa-flag"></i> BOOM </my-wicked-button>
https://github.com/angular/angular.js/issues/4357 (2013-present)
<my-wicked-button>
<div name="hint">
<i class="fa fa-flag"></i> A hint when you hover
</div>
<div name="main">
<i class="fa fa-flag"></i> BOOM
</div>
</my-wicked-button>
vs.
<button my-wicked-button>
<i class="fa fa-flag"></i> BOOM
<my-wicked-hint>
<i class="fa fa-flag"></i> A hint when you hover
</my-wicked-hint>
</button>
Incrementally add attribute directives as needed
Incremental enhancement
Use what you need -- not The Kitchen Sink(tm)
A little less magic
Well, duh.
However...
Some Angular devs didn't get the memo.
Polymer... Well designed, thought out for usability... But very strict styling rules.
<my-alerts val="alertsArr"></my-alerts>
$scope.alertsArr = [{
type: 'danger',
message: 'You failed to do something',
onResolve: function() {
console.log('closed by the user');
}
}];
<div ng-repeat="alert in alertsArr"
class="alert alert-type-{{alert.type}}"
on-resolve="alert.onResolve()">
{{alert.message}}
</div>
$scope.alertsArr = [{
type: 'danger',
message: 'You failed to do something',
onResolve: function() {
console.log('closed by the user');
}
}];
(outdated, but was very popular) | requires jQuery
<div class="gridStyle" ng-grid="gridOptions">
$scope.myData = [{name: "Moroni", age: 50},
{name: "Tiancum", age: 43},
{name: "Jacob", age: 27},
{name: "Nephi", age: 29},
{name: "Enos", age: 34}];
(in beta) | Angular sole dependency | high performance | 'plugin architecture'
... No remote data. Load once. ...ish
<div ui-grid="{ data: myData }" class="myGrid"></div>
$scope.myData = [
{
"firstName": "Cox",
"lastName": "Carney"...
(outdated) | Angular sole dependency
<smart-table rows="rowCollection"></smart-table>
scope.rowCollection = [
{firstName: 'Laurent', lastName: 'Renard', birthDate: new Date('1987-05-21'), balance: 102, email: 'whatever@gmail.com'},
{firstName: 'Blandine', lastName: 'Faivre', birthDate: new Date('1987-04-25'), balance: -2323.22, email: 'oufblandou@gmail.com'},
{firstName: 'Francoise', lastName: 'Frere', birthDate: new Date('1955-08-27'), balance: 42343, email: 'raymondef@gmail.com'}
];
(stable) | sole Angular dependency
<table ng-table="tableParams" class="table">
<tbody>
<tr ng-repeat="user in $data">
<td data-title="'Name'">
{{user.name}}
</td>
<td data-title="'Age'">
{{user.age}}
</td>
</tr>
</tbody>
<tfoot>
<tr>
<td class="text-success text-right"><strong>Summary:</strong></td>
<td>{{sum}}</td>
</tr>
</tfoot>
</table>
<table st-table="rowCollection" class="table table-striped">
<thead>
<tr>
<th>first name</th>
<th>last name</th>
<th>birth date</th>
<th>balance</th>
<th>email</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="row in rowCollection">
<td>{{row.firstName}}</td>
<td>{{row.lastName}}</td>
<td>{{row.birthDate}}</td>
<td>{{row.balance}}</td>
<td>{{row.email}}</td>
</tr>
</tbody>
</table>
scope.rowCollection = [
{firstName: 'Laurent', lastName: 'Renard', birthDate: new Date('1987-05-21'), balance: 102, email: 'whatever@gmail.com'},
{firstName: 'Blandine', lastName: 'Faivre', birthDate: new Date('1987-04-25'), balance: -2323.22, email: 'oufblandou@gmail.com'},
{firstName: 'Francoise', lastName: 'Frere', birthDate: new Date('1955-08-27'), balance: 42343, email: 'raymondef@gmail.com'}
];
Just because it claims it 'uses Angular', doesn't mean that helps YOU during when consuming it
Shoutout: Docker rocks my world. Talk to me about it afterwards.