angularjs - How to use radio buttons with Angular ng-repeat on a Rails collection, with a default value -


i'm angular newbie, , having issues using ng-repeat against rails collection.

i have rails collection of accounts associated user: current_user.accounts

i'm trying use ng-repeat iterate through collection, , have radio buttons user select primary account. radio button should set whichever current primary account (as determined attribute on account, account.is_primary = true). can't seem work @ all. i'm vaguely trying do:

    table.pure-table.pure-table-striped   thead     tr       th name       th account       th primary account    tbody ng-controller="miscaccountctrl"     div ng-repeat="account in accounts"       tr.collapsible         td           .slider ng-class="isopen"             .cell-container {{ account.account_type }}         td           .slider ng-class="isopen"             .cell-container= {{ account.name }}         td           .slider ng-class="isopen"             .cell-container               input type="radio" ng-model="primary" ng-change='setprimary(#{ account.id })' 

the specific problems having are: 1) can't figure out how bind rails collection (current_user.accounts) $scope variable such can "account in accounts".
2) how have radio buttons pre-selected whichever current primary account

i think have sense of how rest, i.e. how set new primary once new radio button selected (using ng-change call directive), can't basic setup right. appreciated.

dc

the biggest problem have not binding object ng-model. ng-repeat creates child scope every repeated item. when use primitive in ng-model loses 2 way binding in child scope because primitives don't have inheritance.

so start object in controller object gets inherited child scopes. ng-model take care of creating object properties if don't exist

$scope.formdata ={}; 

then in html:

input type="radio" ng-model="formdata.primary" 

golden rule: have dot in ng-model ....or []


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -