2015-10-08 30 views
1

我試圖使用表單中的選擇欄將貓鼬對象添加到另一個貓鼬對象。所有其他鍵值對插入正確,即使是複選框布爾,但選擇選項組合不會保存我以前做過的沒有問題,但在離子,它似乎並不想工作。有沒有工作,或者我只是在代碼中搞點東西?選擇選項不在離子中添加對象

$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>

回答

0

嘗試通過VAR controllerName使用他們使用var controllerName = this這個視頻教程,內部控制器和參考的方法和控制器的性能,例如這是一個控制器:

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/