angularjs components getting a form inside template
The name
attribute of a form is what angular uses to decide what to bind to. So, if you're using the controllerAs syntax, you have to use that in the form name:
<body ng-controller="MainCtrl as vm"> <form name='vm.myForm'> </form> </body>
This will allow you to refer to it in your controller without using $scope, but only after the controller has been successfully created:
app.controller('MainCtrl', function($scope, $timeout) { var vm = this; console.log(vm.myForm); // undefined $timeout(function() { console.log(vm.myForm); // FormController object }, 100);});
Here is a working plunk.
Use the name syntax but also a components postLink lifecycle hook, that function is called once a template and controller have been connected see https://docs.angularjs.org/guide/component