javascript - Angular.js - does form validation emit any events? -


the problem is, i'm using ui-router , have 2 views, 1 kind of toolbar, second content form.

now i'd have save button in toolbar, disabled if form not $valid. 2 on different scopes, it's like:

  • rootscope
    • toolbar scope
    • content scope(with form.$valid)

so thought i'd deal listening on kind of $valid events emitted form.

according vojta said here events should exist, can't find them specified anywhere.. , looking @ this don't see events..

i do

$scope.$watch('form.$valid', function(newval, oldval) {    $scope.$emit('validitychange', {'form':newval}); }); 

but feels using events rather better

or should try different? note can't put toolbar's ui-view inside content's ui-view.. , accordin this, 2 ui-views can't have same scope.

to answer question directly: not aware of native form events in angularjs. but, know, can create own events , solve problem.

but here suggestion: trying make 2 controllers communicate each other. using events may wrong approach. events should used application wide notifications such authentication.

you can refactor form , submit button 2 directives share same controller. while not share scope, share controller object can used communicate. way.

another approach nest 2 scopes each other. move form code higher level controller. this:

  • rootscope
    • main // form code here
      • toolbar // submit button has access functionality
      • content // form has access functionality

hope helps!


Comments