-
Notifications
You must be signed in to change notification settings - Fork 27.4k
feat(ngForm): Supports expressions in form name #3115
Conversation
<form name="ctrl.form"> form controller will accessible as $scope.ctrl.form instead of $scope['ctrl.form'] BREAKING CHANGE: If you have form names that will evaluate as an expression: <form name="ctrl.form"> And if you are accessing the form from your controller: Before: function($scope) { $scope['ctrl.form'] // form controller instance } After: function($scope) { $scope.ctrl.form // form controller instance } This makes it possible to access a form from a controller using the new "controller as" syntax. Supporting the previous behavior offers no benefit.
Awesome! This is definitely needed. Very annoying today to need to structure my forms to avoid having them hidden inside child scopes. IMO. dot notation in a form name should be a de facto best practice (just like it is for |
+1 |
This makes sense. +1 |
PR Checklist (Minor Feature)
|
@petebacondarwin I signed the CLA (name is Matthew Windwer) What else do you need from me? I can take care of the documentation update as well, if that's necessary. |
Made a minor change (removed Thanks! |
@btford great! Just out of curiosity, where is |
Sounds like a great change. I have a question though: How to call $apply with this new change? this.$apply gives an error. Also, how private function for e.g. privateFunction below can access 'this' objects? angular.module('demo') var privateFunction = function() { |
@bilalahmed70 I think you are referring to the "controller as" syntax that was introduced in 1.1.5, as this PR just deals specifically with form names. Anyway you are correct that you cannot call A private function within a controller is going to have a different |
@damrbaby Yes, I was referring to the "controller as" syntax. I thought this is set to $scope like this 'this = $scope' but I guess that's not the case. I use $scope.$apply as it is required for third party library calls like firebase or parse. Appreciate your response! Thanks. |
Now it is possible to access a form from a controller using the new
controller as
syntax, without having to access$scope
:Old way:
...
New way:
...