我试图了解ng-if和范围.据我所知,ng-if创建了一个新的子范围.这是我的问题:
视图
<input ng-model="someValue1" />
<div ng-if="!someCondition">
<input ng-model="$parent.someValue2" />
</div>
Run Code Online (Sandbox Code Playgroud)
调节器
$scope.someCondition = true;
if ($scope.someCondition) {
$scope.someValue2 = $scope.someValue1;
}
Run Code Online (Sandbox Code Playgroud)
如果someCondition设置为true,则someValue2应与someValue1相同.
我的问题是我无法在两种情况下访问someValue2(true或false).我怎么能实现这个目标?