0
雙向數據綁定不在<ion-content>
。我無法獲取$ scope變量的更新值(在這種情況下爲「searchKeyword」)。如果我把<ion-conent>
以外的HTML,那麼它的作品。我很困惑這個behavior.Below代碼工作,雙向數據綁定不起作用<ion-content>
<ion-view view-title="Search" >
<div class="bar bar-header item-input-inset" style="height:52px;">
<label class="item-input-wrapper">
<i class="icon ion-ios-search placeholder-icon"></i>
<input type="search" placeholder="Search" ng-model="searchKeyword" ng-keyup="$event.keyCode == 13 ? search() : null">
</label>
<button class="button button-clear" ng-click="search()">
search
</button>
</div>
<ion-content scroll="true" style="margin-top:50px;" >
</ion-content>
</ion-view>
但低於不:(
<ion-view view-title="Search" >
<ion-content scroll="true" style="margin-top:50px;" >
<div class="bar bar-header item-input-inset" style="height:52px;">
<label class="item-input-wrapper">
<i class="icon ion-ios-search placeholder-icon"></i>
<input type="search" placeholder="Search" ng-model="searchKeyword" ng-keyup="$event.keyCode == 13 ? search() : null">
</label>
<button class="button button-clear" ng-click="search()">
search
</button>
</div>
</ion-content>
</ion-view>
這裏,搜索()「searchKeyword」的功能,我沒有得到更新值。下面是我的控制器,
angular.module('myapp')
.controller('SearchController',function($scope){
$scope.searchKeyword='';
$scope.search=function(){
console.log('search keyword : '+$scope.searchKeyword);
};
})
在
search()
這可能是因爲在您的作用域層次結構中的某個位置創建了一個子作用域。然後,當它被分配時,它在子作用域中創建變量的副本,該作用域是父作用域中變量的副本 - 雙向綁定被破壞。嘗試在您的ngModel中添加一個「點」。即$ scope.my.searchKeyword – pixelbits
在你的控制器中初始化$ scope.my = {searchKeyword:''}; – pixelbits
請在http://codepen.io上分享你的例子 –