angularjs ng-model 无法在控制器中访问
angularjs ng-model not able to access in controller
我无法在控制器
中访问此 ng-model 名称 viewProfileCtrl.monthsForm.institution
<select class="perf-select" ng-model="viewProfileCtrl.monthsForm.institution"
ng-options="inst.institution.institution_id as inst.institution.name for inst in viewProfileCtrl.perfiosAnalysisData.institutions"
ng-change="viewProfileCtrl.setCurrMonthInsti(viewProfileCtrl.monthsForm.institution)">
<option value="" selected>Select a Bank</option>
</select>
如果我尝试访问它会显示这样的错误
TypeError: Cannot set property 'institution' of undefined
我如何访问它?
myjs
vm.monthsForm.institution = vm.perfiosAnalysisData.institutions[0].institution.institution_id;
在你的js中,你应该在分配institution
属性之前定义monthsFrom。
你可以这样做:
vm.monthsForm = {
'institution' : vm.perfiosAnalysisData.institutions[0].institution.institution_id;
};
我无法在控制器
中访问此 ng-model 名称viewProfileCtrl.monthsForm.institution
<select class="perf-select" ng-model="viewProfileCtrl.monthsForm.institution"
ng-options="inst.institution.institution_id as inst.institution.name for inst in viewProfileCtrl.perfiosAnalysisData.institutions"
ng-change="viewProfileCtrl.setCurrMonthInsti(viewProfileCtrl.monthsForm.institution)">
<option value="" selected>Select a Bank</option>
</select>
如果我尝试访问它会显示这样的错误
TypeError: Cannot set property 'institution' of undefined
我如何访问它?
myjs
vm.monthsForm.institution = vm.perfiosAnalysisData.institutions[0].institution.institution_id;
在你的js中,你应该在分配institution
属性之前定义monthsFrom。
你可以这样做:
vm.monthsForm = {
'institution' : vm.perfiosAnalysisData.institutions[0].institution.institution_id;
};