我研究了这个问题并找到了使用 php 而不是 angular 的解决方案。
在我的页面上保存数据的要求之一是要求两个单独的 Angular 对象具有相同的 ID。下面是代码:
HTML
<select class="form-control" ng-model="temp" ng-options="type as type.Name for type in Displays">
</select>
AngularJS
$scope.Prop = Prop.data;
$scope.Displays = Displays.data;
我想做的是当在下拉列表中选择 Angular 对象时我想分配 Displays.Id 等于 Prop.TestTemplateId。
我该怎么做?提前致谢
最佳答案
我知道您在下拉框中选择的值绑定(bind)到“$scope.temp”。因此,在初始化 Controller 时,您可以观察该变量并使用新值更新“$scope.testProp.TestTemplateId”,如下所示:
$scope.$watch('temp', function(newType, oldType) {
$scope.Prop.TestTemplateId = newType.Id;
});
这将使..
- Angular 观察“$scope.temp”
- 每当该值发生变化(例如通过下拉列表选择)时,将使用新值(和旧值)调用给定函数
- 在该函数中,您可以更新“$scope.testProp.TestTemplateId”
关于javascript - AngularJS 将选择元素的事件选项设置为不同 Angular 对象的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41558094/