Upgrade to Pro — share decks privately, control downloads, hide ads and more …

angular #4

angular #4

Danila Marchenkov

August 15, 2017
Tweet

More Decks by Danila Marchenkov

Other Decks in Education

Transcript

  1. Validation • ngModel + • ngMinLength | ngMaxLength • required

    | ngRequired • pattern | ngPattern • ngChange
  2. css-classes • ng-valid: the model is valid • ng-invalid: the

    model is invalid • ng-valid-[key]: for each valid key added by $setValidity • ng-invalid-[key]: for each invalid key added by $setValidity • ng-pristine: the control hasn't been interacted with yet • ng-dirty: the control has been interacted with • ng-touched: the control has been blurred • ng-untouched: the control hasn't been blurred • ng-pending: any $asyncValidators are unfulfilled
  3. directive.require angular.module('docsTabsExample', []) .directive('myPane', function() { return { require: ['^^myTabs',

    'ngModel'], restrict: 'E', transclude: true, scope: { title: '@' }, link: function(scope, element, attrs, controllers) { var tabsCtrl = controllers[0], modelCtrl = controllers[1]; tabsCtrl.addPane(scope); }, templateUrl: 'my-pane.html' }; });
  4. Синтаксис • ^ - look for the controller on its

    own element or its parents • ^^ - searches for the controller on its parents • void - directive would look on its own element only
  5. .directive('contenteditable', function() { return { require: 'ngModel', link: function(scope, elm,

    attrs, ctrl) { // view -> model elm.on('blur', function() { ctrl.$setViewValue(elm.html()); }); // model -> view ctrl.$render = function() { elm.html(ctrl.$viewValue); }; // load init value from DOM ctrl.$setViewValue(elm.html()); } }; });