AngularJS - How do I access the form defined inside a templateUrl in my directive? -


i attempting access form inside directive validation purposes, i'd access $setpristine, however, can't seem figure out how form if it's created using templateurl.

i have plunker detailing issue here: http://plnkr.co/edit/sp53xzdtbyxl6daue1uv?p=preview

i'm getting error:

controller 'form', required directive 'testdirective', can't found! 

here relevant plunker code:

.js:

var app = angular.module("myapp", []);  app.directive("testdirective", function() {   return {     restrict: 'e',     scope: {},     templateurl: "formtemplate.html",     require: "^form",  // <-- doesn't work     link: function (scope, element, attrs, ctrl) {       console.log(ctrl);        scope.open = function() {           // have access form here           // ctrl.$setpristine();       }     },     controller: function($scope) {       $scope.firstname = "mark";        $scope.save = function(form) {         console.log(form);       }     }   } }) 

formtemplate.html:

<form name="testform" ng-click="save(testform)">   <input type="text" ng-model="firstname" />   <br>   <input type="submit" value="save" /> </form> 

how can attach form in formtemplate.html isolated scope of directive?

http://plnkr.co/edit/41hhrpkoisz9c8y9yi87?p=preview

try in directive:

var form1 = element.find('form').eq(0); formctrl = form1.controller('form'); console.log(formctrl); 

this should grab controller form.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -