0

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;

};

ninjaXnado
  • 271
  • 1
  • 7
  • 17

4 Answers4

0

You could use ng-true-value and ng-false-value

<input type="checkbox" ng-model="lis.SMSPromotion" id="SMSPromotion" ng-init="checked=true" ng-true-value="1" ng-false-value="0">
Gangadhar Jannu
  • 4,136
  • 6
  • 29
  • 49
  • The error is not related to your html. Check whether the 'SMSPromotion' service/factory is defined before your controller – Gangadhar Jannu Jan 23 '15 at 11:23
  • Call23.factory('data', function ($resource) { return $resource('/api/Person1/:id', { id: '@id' }, { update: { method: 'PUT' } }); }); – ninjaXnado Jan 26 '15 at 06:30
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 ?

Aliz
  • 736
  • 1
  • 11
  • 25
  • Please see this post, (did you initialize your app with the service SMSPromotion ?) http://stackoverflow.com/questions/12339272/angular-js-unknown-provider – Aliz Jan 23 '15 at 09:53
  • Call23.factory('data', function ($resource) { return $resource('/api/Person1/:id', { id: '@id' }, { update: { method: 'PUT' } }); }); – ninjaXnado Jan 23 '15 at 10:10
  • this is what you talking about? – ninjaXnado Jan 23 '15 at 10:10
0

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

Nisham Mahsin
  • 1,399
  • 5
  • 19
  • 43
0

Try this:

 You can have true or false values in check boxes.

<input type="checkbox" ng-model="MyValue" ng-true-value="1" ng-false value="2">

This LINK has an example

Hope it helps...

Alagarasan M
  • 907
  • 8
  • 16