0

HTML

<form role="form" ng-submit="addStore(store)" name="AddStoreForm" novalidate>
    <label>Store Category</label>
        <label class="checkbox-inline"  ng-repeat="store_category in store_cat">
            <input type="checkbox" name="store_category" ng-model="store.store_category">{{store_category.name}}
        </label>
    </label>
 </form>
 <button type="submit" class="btn btn-primary campwidth">SUBMIT</button>

AngularJS

$scope.store_cat = [
    { name: 'A', selected: false },
    { name: 'B', selected: false },
    { name: 'C', selected: false }
];
$scope.addStore = function(store){
    console.log("responsestore", store);
    alert(store.store_category);
};

Here I put store category as array. After submit the form. I got alertbox category undefined. I want to sent the result using API. how to fix this problem. PLUNKER

1
  • can you explain how your example should work? what should happen and when clicking on what? Commented Oct 9, 2015 at 11:49

3 Answers 3

2

It will work with button tag not with form as in bootstrap <button type="submit" class="btn btn-primary campwidth" ng-click="addStore(store_cat)">SUBMIT</button> here no need of using the form tag b'coz it may leads to conflict in angular.js so, it will work definately for checkbox. http://plnkr.co/edit/qSFnxTNZ4n63pw3JXZA5?p=preview

Sign up to request clarification or add additional context in comments.

Comments

0

You can, do something like that: <button type="submit" class="btn btn-primary campwidth" ng-click="addStore(store_cat)">SUBMIT</button> here http://plnkr.co/edit/KtBzqeMF9FZt6bnI0MBF?p=preview You shouldn't use form and take on that function nope, that way is wrong when you use angular.

Comments

0

Assuming your issue is with data format not being pushed into a new store object, here is a solution for that:

<form role="form" name="AddStoreForm" novalidate ng-init="store={}">
  <label>Store Category</label>
  <label class="checkbox-inline" ng-repeat="store_category in store_cat">
    <input type="checkbox" name="store_category" ng-init="store[$index]={name: store_category.name, selected: false}" ng-model="store[$index].selected">{{store_category.name}}
  </label>
  </label>
  <button type="submit" ng-click="addStore(store)"  class="btn btn-primary campwidth">SUBMIT</button>
</form>

And the plunker with working example.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.