How can I pass a variable from controller to HTML template?

okay so the directive {{array[0].name}} in the HTML will display the first name in the array. I have an if statement controlling a variable like so:

if ( int <= 0 ) iNum = 0
else if ( int > 100 ) iNum = 1
else iNum = int

what i need to do is have the HTML display {{array[iNum].name}} so the angular parse will display the name from that id…

is there an easy way to pass a javascript variable in the controller to the HTML?

On suggestion from the IRC room was to create a separate directive but that has created more problems and gets really meta cause my directive would call another directive just output a string that would than be parsed properly. convoluted aside, I tried it but was unable to get that solution to work anyway.

so is there a way for me to solve this without getting to crazy? the first thoughts I have seem like serious overkill for what I am trying to accomplish.


Replace iNum by $scope.iNum in the javascript and let {{array[iNum].name}} in HTML

1 Like


saved me so much hassle, this worked perfectly.