[英]How to hide the text and checkbox when checked to remove in AngularJS?
[英]AngularJS Printing text if checkbox is checked
我試圖根據<h1>
標簽在頁面上打印文本,具體取決於是否選中了復選框。
$scope.EmailMe = function(email) {
if($scope.emailchecked == 1) {
$scope.test = "emailSent";
} else {
$scope.test = "nothing";
}
}
HTML是:
<input type="checkbox" ng-model="emailchecked" ng-change="EmailMe(1)">
<h1> @{{test}} </h1>
我正在打印文本,但未選中該復選框。 或允許更改,請幫助:)
采用ng-true-value
和ng-false-value
,這樣會給你1
/ 0
基於選擇值。
<input type="checkbox" ng-model="emailchecked"
ng-true-value="1"
ng-false-value="0"
ng-change="EmailMe(emailchecked)">
即使您不使用ng-true-value
,但這也不會使您將value建模為0/1。 默認情況下,復選框的值為true / false。
HTML
<body ng-controller="MainCtrl">
<input type="checkbox" ng-model="emailchecked" ng-change="EmailMe()">
<h1> @{{test}} </h1>
</body>
調節器
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.name = 'World';
$scope.EmailMe = function() {
if($scope.emailchecked == 1) {
$scope.test = "emailSent";
} else {
$scope.test = "nothing";
}
};
});
http://plnkr.co/edit/EfIMMn7Be7QL258aUiXW
並在您的代碼中更改了emailchecked
。
您需要將if(email = 1)更改為if(email == 1)。 一個相等的缺失
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.