Created by Aidas Klimas
I code mostly with - JavaScript and PHP
I share stuff at - https://github.com/AidasK
Angular makes HTML Dynamic, you can create any html element, attribute you want
<tabset><tab></tab></tabset>
<grid>
<lightbox src="image.png" />
<pokemon name="Pikachu"/>
<a blink="2000">
<ul>
{{#each visitors}}
<li>Hello, {{name}}!</li>
{{/each}}
</ul>
<ul>
<li ng-repeat="visitor in visitors">Hello, {{visitor.name}}!</li>
</ul>
HTML string + Data = Merged HTML string
<!doctype html>
<html ng-app>
<head>
<script src="js/angular.js"></script>
</head>
<body>
<label>Name:</label>
<input type="text" ng-model="yourName">
<h1>Hello {{yourName}}!</h1>
</body>
</html>
<div ng-init="boxes=[]">
<button class="btn btn-default" ng-click="boxes.push({
id: boxes.length + 1
})">Add box</button>
<div ng-repeat="box in boxes" class="box">{{box.id}}</div>
</div>
<greeter name="Pikachu"></greeter>
Should output:
Hello Pikachu!
app.directive('greeter', function () {
return {
restrict: 'E',
template: 'Hello {{name}}!',
scope: {
name: '@'
}
};
});
<greeter name="Angular"></greeter>
<greeter name="Kaunas"></greeter>
Outputs:
<directive></directive>
<div directive></div>
<img src="images/datadog.png" draggable/>
Example:
app.directive('draggable', function($document) {
return function (scope, element, attr) {
var startX = 0, startY = 0, x = 0, y = 0;
element.css({
position: 'relative', cursor: 'pointer'
});
element.on('mousedown', function (event) {
startX = event.pageX - x;
startY = event.pageY - y;
$document.on('mousemove', mousemove);
$document.on('mouseup', mouseup);
event.preventDefault();
});
function mousemove(event) {
y = event.pageY - startY;
x = event.pageX - startX;
element.css({
top: y + 'px',
left: x + 'px'
});
}
function mouseup() {
$document.unbind('mousemove', mousemove);
$document.unbind('mouseup', mouseup);
}
}
});
app.directive('awesomeClick', function($document) {
return function (scope, element, attr) {
scope.awesome = 0;
element.bind('click', function () {
scope.awesome += 1;
});
}
});
<a awesome-click>awesome-click [{{awesome}}]</a>
awesome-click [{{awesome}}]
app.directive('runApplyClick', function($document) {
return function (scope, element, attr) {
element.bind('click', function () {
scope.$apply();
});
}
});
run-apply-click
app.directive('awesomeClickFixed', function($document) {
return function (scope, element, attr) {
scope.awesome = 0;
element.bind('click', function () {
scope.awesome += 1;
scope.$apply();
});
}
});
<a awesome-click-fixed>awesome-click-fixed [{{awesome}}]</a>
awesome-click-fixed [{{awesome}}]
Make sure event is always called sync or async
This is not a solution
if (!$scope.$$phase) $scope.$apply()
Solution:
scope.$evalAsync(function () {
// Ugly code goes here
});
No more $scope.$apply()!
app.factory('$log', function($window){
return {
log: consoleLog('log'),
info: consoleLog('info'),
warn: consoleLog('warn'),
...
};
function consoleLog(type) {
return function() {
var args = [];
forEach(arguments, function(arg) {
args.push(formatError(arg));
});
return logFn.apply(console, args);
};
}
});
Send all errors to the server side.
...
function consoleLog(type) {
return function() {
var args = [];
forEach(arguments, function(arg) {
args.push(formatError(arg));
});
var url = $window.location && $window.location.href;
$http.post('/log', {message: args.join('\n\n'), url: url});
return logFn.apply(console, args);
};
}
...
<html ng-app>
<head>
<link rel="stylesheet" type="text/css" href="/css/min.css"/>
<script type="text/javascript" src="/js/min.js"></script>
<title>My Angular site</title>
</head>
<body>
<div ng-view></div>
</body>
</html>
<meta name="fragment" content="!"/>
$locationProvider.hashPrefix('!');
http://example.com/#!/article
http://example.com/?_escaped_fragment_=/article
$locationProvider.html5Mode(true).hashPrefix('!');
http://example.com/article
http://example.com/article?_escaped_fragment_=
JavaScript library providing multiple simultaneous, stable and resumable uploads via the HTML5 File API.
github.com/flowjs/ng-flow
Get slides from klimas.lt/slides