I am trying to understand ng-if and scopes. As I am aware, ng-if creates a new child scope. Here is my issue:
View
<input ng-model="someValue1" />
<div ng-if="!someCondition">
<input ng-model="$parent.someValue2" />
</div>
Controller
$scope.someCondition = true;
if ($scope.someCondition) {
$scope.someValue2 = $scope.someValue1;
}
If someCondition is set to true, then someValue2 should be the same as someValue1.
My problem is that I can't access someValue2 in both situations (true or false). How could I achieve this?
$parent.someValue.num = 10, don't :$parent.someValue = 10$parentproperties seems to work perfectly fine. The "already answered here" question at the very top has an answer that explains how modifying$parentproperties works, even with some visualization, and it clearly shows that it works. One problem is that when adding more conditions andng-ifs or creating some other child scopes, there may be a longer chain of$parents and the code breaks, unlike when using objects. Actually, you don't even need$parentwhen using those objects, just use$scope:$scope.someValue.num = 10.