javascript - Using ng-click on the same tag as ng-repeat with argument from ng-repeat scope -


i have select list populated ng-repeat tag list of objects. name property of each of these objects displayed in tag. on click of 1 of these tags want invoke function ng-click, passing url property of these objects argument.

the populating part working fine, doesn't seem passing of argument works. here comes code:

the html:

<div ng-controller="taskchartctrl">   <select>     <option ng-repeat="project in projectlist" ng-click="populategraphs(project.url)">{{ project.name }}</option>   </select> </div> 

the relevant part controller:

 myapp.controller("taskchartctrl", ["$scope", "$http", function ($scope, $http) {          $scope.projectlist = {};      $http.get('url', config).then(function(response) {         $scope.projectlist = response.data.projects;     }, function(errresponse) {         console.error("error fetching projectlist");     });       $scope.populategraphs = function(projecturl) {       //function code goes here     } }]); 

could point me in right direction mistake is?

thanks lot!

since using <select>, need use ng-change instead of ng-click

also use ng-options instead of ng-repeat <select>

reference : select options through ng-click not working in chrome browser using angularjs

try this, set selectedproject inside populategraphs function while changing

<select ng-model="selectedproject" ng-options="project project.name project in projectlist" ng-init="selectedproject = 'someprojectname'" ng-change="populategraphs(selectedproject.url)"> <option value="">select project</option> </select> 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -