how can i achieve to create a checkbox?

I'm trying to set a checkbox to true with Angularjs. When i save it must save an integer (1 or 0) on my field.

Here is the view:

 <input type="checkbox" ng-model="lis.SMSPromotion" id="SMSPromotion" ng-init="checked=true" >

app.js

 $scope.lis.SMSPromotion = true;

Model

public Nullable<int> SMSPromotion { get; set; }

i have this error Error:

[$injector:unpr] Unknown provider: SMSPromotionProvider <- SMSPromotion

Controller

var CreateCtrl = function ($scope, $location, data, $filter,SMSPromotion ) {
    $scope.save = function () {
      data.save($scope.lis, function () {
        $location.path('/')
    });

};
$scope.lis.SMSPromotion = true;

};


你可以使用ng-true-value和ng-false-value

<input type="checkbox" ng-model="lis.SMSPromotion" id="SMSPromotion" ng-init="checked=true" ng-true-value="1" ng-false-value="0">

"[$injector:unpr] Unknown provider: SMSPromotionProvider <- SMSPromotion"

That error means, that you forgot to inject the service "SMSPromotion" in your controller.

Could you show us your controller ?


you can do

<input type="checkbox"  ng-checked="myScope=='Y'" ng-model="myScope" value="anything" />

and in controller you can make

$scope.myScope='Y' or $scope.myScope='N'

see this fiddle

链接地址: http://www.djcxy.com/p/77642.html

上一篇: 未知的提供者

下一篇: 我怎样才能创建一个复选框?