简体   繁体   中英

angular js, passing data as parameter from view to controller

I'm tryng to get data from view that must be passed as parameter in a function to populate an array in the controller. But the objects return me nothing, here what i have done:

VIEW

        <div ng-repeat="cssframework in voce.framewrok">
        <input type="checkbox" ng-onchange="AggiornaTotale({{cssframework.costo}})"/>  
        <span>{{cssframework.name}}........<b>{{cssframework.costo | currency}}</b></span>
      </div>    
<div class="row">
    <h3>TOTALE: {{selectedVoices[0]}}</h3>
</div>

ng-onchange trigger the function "AggiornaTotale" and pass cssframework.costo as parameter, the goal in the controller, is to populate an array named "selectedVoices"

CONTROLLER

    $scope.AggiornaTotale = function(param) {
    $scope.selectedVoices = [];
    this.selectedVoices.push(param);
}   

Why i don't see {{selectedVoices[0]}} updated? Thank you for advice

ng-change替换ng-onchange

change

ng-onchange="AggiornaTotale({{cssframework.costo}})

to

ng-change="AggiornaTotale({{cssframework.costo}})

and controller to

 $scope.AggiornaTotale = function(param) {
    $scope.selectedVoices = [];
    $scope.selectedVoices.push(param);
 }   

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM