选定的选项更改时,模型不会更新

时间:2016-03-08 23:22:48

标签: javascript angularjs angularjs-scope angularjs-ng-model

我的Angular.js项目具有绑定到模型的select元素。在加载时,选择了适当的选项,但是选择另一个选项似乎并不能更新模型,至少不是永久性的。如果我以编程方式更改模型,但结果与预期一致。

控制器:

angular.module('myApp.controllers').controller('HomeCtrl',function($scope){
  $scope.month = "08"; // this default value is selected on-load as expected
  $scope.updateMonth = function() {
   console.log($scope.month); // this shows the original value not the newly selected value
   // a http request and other things happen here...
  };
  $scope.logMonth = function(month) {
   console.log(month); // this shows the newly selected value as expected
  }
 });

模板:

<select ng-model="month" ng-change="logMonth(month);">
 <option value="07">07</option>
 <option value="08">08</option>
 <option value="09">09</option>
</select>
<button ng-click="updateMonth();">Update Month</button>

1 个答案:

答案 0 :(得分:0)

听起来像角度范围问题。范围继承适用于范围内的对象,但不适用于基元。尝试将 #df is a dataframe num_rows = len(df) #Iterate one row at a time for i in range(num_rows): try: #Try inserting the row df.iloc[i:i+1].to_sql(name="Table_Name",con = Engine_Name,if_exists = 'append',index=False) except IntegrityError: #Ignore duplicates pass 更改为$scope.month = "08"。然后在您的控制器中,将html更改为以下内容。

$scope.month = {selected: "08"}