2017-03-31 48 views
0

在指令中,我們設置了$scope.checkValue = true,並將相同的作用域傳遞給ngstrap模態對話框。複選框未在ngstrap模式對話框中更新模型

下面

是向鏈路功能的代碼被稱爲按鈕點擊彈出對話框:

return { 
     templateUrl: "../Views/userSubscriptionView.html", 
     restrict: 'E', 
     scope: {}, 
     link: function ($scope, element, attributes) { 
$scope.checkValue = false; //this is bind to checkbox model but not updating on check/uncheck. 
    function DoOpenDialog() 
    { 
     //other code 
     var myOtherModal = $modal({ scope: $scope, templateUrl: "../Views/SubscribePopup.html", show: false , persist:false}); 
           myOtherModal.$promise.then(myOtherModal.show); 
    } 

下面是對話代碼:

<input type="checkbox" ng-model="checkValue"/> 
{{checkValue}} 

的問題是:當我選中複選框爲true或false,模型'checkValue'不更新。我需要根據複選框檢查狀態更改其他控件的狀態。

感謝

+0

發佈您的指令代碼以幫助更多。 – Aravind

+0

沒有更多的代碼,它是不可能知道你的問題是什麼,但它可能是由於[JavaScript Prototype Inheritance]有問題(http://stackoverflow.com/questions/14049480/what-are-the -nuances的範圍外-原型-原型繼承功能於angularjs)。一般來說,你應該**總是在角度綁定中使用一個點**。 – Claies

+0

更新後的帖子更詳細。 –

回答

0

我用顯式設置ng-true-valueng-false-value屬性來解決這個問題:

<input type="checkbox" 
    ng-true-value="'true'" 
    ng-false-value="'false'" 
    ng-model="checkValue" 
/> 

通知各地'true'單引號。最終,所有內容都以字符串形式傳遞,而不是布爾或整數。當我必須處理來自mysql的布爾(tinyint)0/1值時,我使用相同的方法:ng-true-value="'1'"等等。