드롭 다운 옵션의 선택한 값에 액세스하려고합니다. 그러나 문제는 이미 부모 div로 ng-repeat가 있고 드롭 다운의 옵션도 ng-repeat를 사용하고 있다는 것입니다. 기본적으로 중첩 된 ng-repeat입니다.
따라서 선택한 값에 액세스 할 수 없습니다.
<div ng-controller="csrClrt">
<div ng:repeat="item in items track by $index">
<md-list one class="md-accordion">
<md-input-container>
<label>Face Style:</label>
<md-select ng-model="style">
<md-option ng-value="user.name" ng:repeat="user in styles">{{user.name}}</md-option>
</md-select>
</md-input-container>
</md-list>
</div>
<div>
<input type="button" value="get selected value" ng-click="getvalue()"/>
</div>
<p>
if i ttry out of parent ng repeat
</p>
<md-input-container>
<label>Face Style:</label>
<md-select ng-model="style">
<md-option ng-value="user.name" ng:repeat="user in styles">{{user.name}}</md-option>
</md-select>
</md-input-container>
<div>
<input type="button" value="get selected value" ng-click="getvalue()"/>
</div>
</div>
AngularJS
angular.module('MyApp', ['ngMaterial'])
.controller('csrClrt', function ($scope) {
$scope.items=["0"];
stylesdata=[{name:"a"},{name:"b"},{name:"c"}];
var style=[];
for(var i=0;i<stylesdata.length;i++)
{
style.push({
name:stylesdata[i].name
})
}
$scope.styles=style;
$scope.getvalue=function()
{
alert($scope.style);
}
})
반복은 격리 된 범위없이 수행하려는 경우 범위를 격리 한 다음 변수를 이와 같은 독립 변수가 아닌 개체로 바인딩합니다.
<md-select ng-model="a.style">
다음으로 액세스
alert($scope.a.style);
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다