carelesslyChoosy carelesslyChoosy - 6 months ago 10
Javascript Question

How to use Functional $scope methods in HTML templates without using ng-click?

I am learning angular for my next project, I am confused how to use a $scope variable (call the function) in my template file, all the example I could find use it with ng-click, or more general how to access business logic of the controller in templates views? for example I have this function

$scope.rows = function(){
var rowNumber;
rowNumber = Math.floor($scope.itemNumber / 6);

var rows = [];
for(var i = 0; i < rowNumber; i++){
rows.push('row'+ i);
console.log(rows);
}

return rows;
};


I want to access this rows array which is getting dynamically generated in ng-repeat?

Answer

its easy, just use

<div ng-repeat="row in rows()">
   <span>{{ row }} </span>
</div>

here is more information about ng-repeat https://docs.angularjs.org/api/ng/directive/ngRepeat