我尝试使用表单中的选择栏将猫鼬对象添加到另一个猫鼬对象。所有其他键值对都插入正确,甚至复选框bool,但select-option组合不会保存我之前完成此操作没有问题,但在离子中,它不会似乎想要工作。有没有解决方法,或者我只是在代码中弄乱了什么?
$scope.addProperty = function(prop){
console.log(prop);
Props.add(prop)
.then(function(res) {
console.log(res.data);
//window.location.reload();
})
.catch(function(error){
console.log(error);
});
};

<form method = "post" class="form-inline" role="form" action = "localhost:3000/managers/newApt">
<div class="form-group">
<label class="sr-only" >Tenants:</label>
<select ng-model="prop.tenants" class="column medium-3" ng-options="manager.name for manager in allManagers"> </select>
</div>
<div class="form-group">
<label class="sr-only">Address</label>
<input type="text" class="form-control" ng-model='prop.address'>
</div>
<button type="submit" class="btn btn-default" ng-click='addProperty(prop)'>Add Property</button>
</form>
&#13;
答案 0 :(得分:0)
尝试使用这个视频教程,他们使用var controllerName = this
,通过var controllerName
控制器和参考方法以及控制器的属性,例如这是一个控制器:
angular
.module('your-app-module')
.controller('ExampleController', function ($scope, $state) {
//This var is to bind methods and vars in view(html) to this specific controller
var ExmpleCtrl = this; //this is the var that is going to replace $scope
//NOTICE no $scope but rather ExmpleCtrl
ExmpleCtrl.goToState = function (state) {
$state.go(state);
};
});
现在在你的html尝试:
<ion-view ng-controller="ExampleController as exmpleCtrl">
<ion-content>
<!-- notice how I use exmpleCtrl instead of $scope to access controller or to pass info -->
<div ng-click="exmpleCtrl.doSomething()">
</ion-view>
如果你还有疑问请查看这个简短的视频(忽略它的webstorm,它们将控制器绑定到控制器内部的变量的方式,这是有用的):http://blog.jetbrains.com/webstorm/2014/03/angularjs-workflow-in-webstorm/