Created by Victor Mejia
Software Dev @ LoopNet (CoStar Group)
I ♥ JavaScript
Tweeting @victorczm
Coding @victormejia
Blogging @ victormejia.me
option for finding places in your app that won't minify correctly because of the DI syntax
{{message}}
angular.module('app', [])
.controller('MyCtrl', function ($scope, $filter) {
$scope.message = "hello";
});
// that could be minified to this: what is a?
angular.module('app', []).controller('MyCtrl', function (a, b) {a.message = "hello"; });
angular.module('app', [])
.controller('AppCtrl', ['$scope', '$filter',
function ($scope, $filter) {
$scope.message = "hello";
}]);
function AppCtrl($scope, $http, $filter) {
// ...
}
AppCtrl.$inject = ["$scope", "$http", "$filter"];
angular.module("myApp", [])
.controller("AppCtrl", AppCtrl)
prefix bindings with "::", then only interpolated once and no longer watched
Hello, my name is {{userName}}
{{userName}}
is an interpolation directive"one-time expressions will stop recalculating once they are stable, which happens after the first digest if the expression result is a non-undefined value"
Hello, my name is {{::userName}}
allows us to control how ngModel updates are done
update model (trigger $digest)...
Search: {{searchText}}
specify an object with either 'default' or 'blur' props
Search: {{searchText}}
user.name =
var _age = 27;
$scope.user = {
age: function (newAge) {
if (angular.isNumber(newAge) && newAge > 0) {
return ($scope.age = newAge);
}
return $scope.age;
}
}
user.age =
manages the logic of passing values b/n DOM and scope and handles parsing, formatting, validation
// userForm.email.$error
{
"email" : true
"required": false,
}
src: http://www.yearofmoo.com/2014/09/taming-forms-in-angularjs-1-3.html
src: http://www.yearofmoo.com/2014/09/taming-forms-in-angularjs-1-3.html
You did not enter an email.
You did not enter a valid email.
//
//
//
app.directive('customValidator', function() {
require : 'ngModel',
link : function(scope, element, attrs, ngModel) {
ngModel.$validators.myValidator = function() {
// return true or false
}
}
});
return a promise
ngModule.directive('usernameAvailableValidator', ['$http', function($http) {
return {
require : 'ngModel',
link : function($scope, element, attrs, ngModel) {
ngModel.$asyncValidators.usernameAvailable = function(username) {
return $http.get('/api/username-exists?u='+ username);
};
}
}
}])
$scope.submit = function (valid) {
if (!valid) return;
$http.post(...)
}
© 2014 PEANUTS Worldwide LLC