Перевод/формат статьи “Sane, scalable Angular apps are tricky, but not impossible. Lessons learned from PayPal Checkout.”
(Очень радует, что на зло всем критикам появляется все больше и больше серьезных приложений на AngularJS)
Перевод/формат статьи “Sane, scalable Angular apps are tricky, but not impossible. Lessons learned from PayPal Checkout.”
(Очень радует, что на зло всем критикам появляется все больше и больше серьезных приложений на AngularJS)
Небольшая заметка о том, для чего нужны $formatters и $parsers в контроллере ngModel директивы и когда их можно применять.
Вкратце:
I was just curious about this discussion on stackoverflow and decided to do own test:
[javascript]
for(var i = 0; i < 100000; i++){
randomKey = randomString();
bigScope1[randomKey] = randomString();
bigScope2[randomKey] = randomString();
bigNgBindTempalte += ‘<div class="’ + randomString() + ‘" ng-bind="’+ randomKey + ‘"></div>’;
bigExpressionTemplate += ‘<div class="’ + randomString() + ‘">{{‘ + randomKey + ‘}}</div>’;
}
// console.time(‘ngBind’);
// $compile(‘<div>’ + bigNgBindTempalte + ‘</div>’)(bigScope1);
// console.timeEnd(‘ngBind’);
console.time(‘expression’);
$compile(‘<div>’ + bigExpressionTemplate + ‘</div>’)(bigScope2);
console.timeEnd(‘expression’);
[/javascript]
code.
and indeed ngBind is faster,my machine for 100000 iterations shows:
ngBind: 46984.981ms expression: 51107.555ms
It’s still not clear why the result are so weird when you run it together (one by one). But it’s another question.
Dragula is a light weight library(or module) for applying drag&drop functionality on you application. There is also an official AngularJS adapter for it – angular-dragula.
It has quite strange module dependancy declaration:
[javascript]
var app = angular.module(‘my-app’, [angularDragula(angular)]);
[/javascript]
so I put an example on plunker to make it easy for you to start.
ng-stats is nice utility from Kent C. Dodds that allows you to see statistics for your page’s angular digest/watches.
to install just put this code into your bookmarks:
[javascript]
javascript: (function() {var a = document.createElement("script");a.src = "https://rawgithub.com/kentcdodds/ng-stats/master/dist/ng-stats.js";a.onload=function(){window.showAngularStats()};document.head.appendChild(a)})();
[/javascript]
Just a checklist to prevent issues with application migration.
fixed strange behaviour (from 1.3): before ‘f’, ‘0’, ‘false’, ‘no’, ‘n’, ‘[]’ have been converted to false. Check you ng-if statements.
.copy() – makes a copy of only own properties (from 1.3)
.forEach() – does not take in account new elements (if during the loop size was changed)(from 1.3)
directive property replace – is now deprecated (from 1.3)
responseInterceptors property was removed from $httpProvider (from 1.3) – now it’s just $httpProvider.interceptors
$cookieStore is deprecated from 1.4 ( you should use $cookie instead)
If you know more tricky places – do not hesitate to share!
Решил выложить пример кода “Controller as” в песочнице, чтобы можно было поиграться и понять, что нельзя миксовать 2 стиля написания контроллеров: либо $scope и писать просто переменные, либо this и делать синтаксис Controller as.
just put it here (taken from @addyosmani)