var app = angular.module('plunker', ["at-on-load-element"]);
app.controller('MainCtrl', function($scope) {
$scope.name = 'World';
$scope.list = [{id:1},{id:2}];
});
<!DOCTYPE html>
<html ng-app="plunker">
<head>
<meta charset="utf-8" />
<title>AngularJS Plunker</title>
<script>document.write('<base href="' + document.location + '" />');</script>
<link rel="stylesheet" href="style.css" />
<script data-require="angular.js@1.1.x" src="http://code.angularjs.org/1.1.5/angular.min.js" data-semver="1.1.5"></script>
<script src="angular-at-on-load-element.js"></script>
<script src="app.js"></script>
</head>
<body ng-controller="MainCtrl">
<p>Hello {{name}}!</p>
<ul>
<li ng-repeat="row in list" at-on-load-element="element.html(element.html()+' bar');">
foo {{ row.id }}
<span at-on-load-element-from-last="element.html(element.html()+' baz');"></span>
</li>
</ul>
</body>
</html>
/* Put your css in here */
###*
* angular at-on-load-element
*
* @author atomita
* @license MIT
* @version 0.0.1
###
angular.module("at-on-load-element", []).directive("atOnLoadElement", ["$timeout", ($timeout)->
{
restrict: "AC"
scope: true
link: (scope, iElement, iAttrs)->
apply = iAttrs.atOnLoadElement
if apply
scope.element = iElement
scope.attrs = iAttrs
scope.angular = angular
$timeout -> scope.$apply(apply)
return
}
]).directive("atOnLoadElementFromFirst", ["$timeout", ($timeout)->
{
restrict: "AC"
scope: true
link: (scope, iElement, iAttrs)->
apply = iAttrs.atOnLoadElementFromFirst
$parent = scope
loop
$parent = $parent.$parent
if $parent
if "$first" of $parent
$first = $parent.$first
break
else
break
if apply and $first
scope.element = iElement
scope.attrs = iAttrs
scope.angular = angular
$timeout -> scope.$apply(apply)
return
}
]).directive("atOnLoadElementFromMiddle", ["$timeout", ($timeout)->
{
restrict: "AC"
scope: true
link: (scope, iElement, iAttrs)->
apply = iAttrs.atOnLoadElementFromMiddle
$parent = scope
loop
$parent = $parent.$parent
if $parent
if "$middle" of $parent
$middle = $parent.$middle
break
else
break
if apply and $middle
scope.element = iElement
scope.attrs = iAttrs
scope.angular = angular
$timeout -> scope.$apply(apply)
return
}
]).directive("atOnLoadElementFromLast", ["$timeout", ($timeout)->
{
restrict: "AC"
scope: true
link: (scope, iElement, iAttrs)->
apply = iAttrs.atOnLoadElementFromLast
$parent = scope
loop
$parent = $parent.$parent
if $parent
if "$last" of $parent
$last = $parent.$last
break
else
break
if apply and $last
scope.element = iElement
scope.attrs = iAttrs
scope.angular = angular
$timeout -> scope.$apply(apply)
return
}
])
/**
* angular at-on-load-element
*
* @author atomita
* @license MIT
* @version 0.0.1
*/
angular.module("at-on-load-element", []).directive("atOnLoadElement", [
"$timeout", function($timeout) {
return {
restrict: "AC",
scope: true,
link: function(scope, iElement, iAttrs) {
var apply;
apply = iAttrs.atOnLoadElement;
if (apply) {
scope.element = iElement;
scope.attrs = iAttrs;
scope.angular = angular;
$timeout(function() {
return scope.$apply(apply);
});
}
}
};
}
]).directive("atOnLoadElementFromFirst", [
"$timeout", function($timeout) {
return {
restrict: "AC",
scope: true,
link: function(scope, iElement, iAttrs) {
var $first, $parent, apply;
apply = iAttrs.atOnLoadElementFromFirst;
$parent = scope;
while (true) {
$parent = $parent.$parent;
if ($parent) {
if ("$first" in $parent) {
$first = $parent.$first;
break;
}
} else {
break;
}
}
if (apply && $first) {
scope.element = iElement;
scope.attrs = iAttrs;
scope.angular = angular;
$timeout(function() {
return scope.$apply(apply);
});
}
}
};
}
]).directive("atOnLoadElementFromMiddle", [
"$timeout", function($timeout) {
return {
restrict: "AC",
scope: true,
link: function(scope, iElement, iAttrs) {
var $middle, $parent, apply;
apply = iAttrs.atOnLoadElementFromMiddle;
$parent = scope;
while (true) {
$parent = $parent.$parent;
if ($parent) {
if ("$middle" in $parent) {
$middle = $parent.$middle;
break;
}
} else {
break;
}
}
if (apply && $middle) {
scope.element = iElement;
scope.attrs = iAttrs;
scope.angular = angular;
$timeout(function() {
return scope.$apply(apply);
});
}
}
};
}
]).directive("atOnLoadElementFromLast", [
"$timeout", function($timeout) {
return {
restrict: "AC",
scope: true,
link: function(scope, iElement, iAttrs) {
var $last, $parent, apply;
apply = iAttrs.atOnLoadElementFromLast;
$parent = scope;
while (true) {
$parent = $parent.$parent;
if ($parent) {
if ("$last" in $parent) {
$last = $parent.$last;
break;
}
} else {
break;
}
}
if (apply && $last) {
scope.element = iElement;
scope.attrs = iAttrs;
scope.angular = angular;
$timeout(function() {
return scope.$apply(apply);
});
}
}
};
}
]);