angularjsng-controller

ng-click function parameters as $scope variable with angular 1.x


I would like to use the parameters that I get with my ng-click as $scope variable to use it everywhere on my site.

My Controller:

music.controller('musicController', function($scope, $rootScope, $location, musicControl) {
  $scope.titles = [
  {
    title: 'New Divide',
    artist: 'Linkin Park',
    album: 'New Divide',
    genre: 'Rock',
    cover: 'new-divide.jpg',
    titleLength: '4:28',
    file: 'test'
  }
  ];
  $scope.playListMusic = function(titleName) {
    $rootScope.titleName = titleName;
    musicControl.playListMusic();
  }
//...
});

My ng-click link:

<div ng-repeat="title in titles | unique:'album' | filter:search" class="row content">
/...
<span ng-click='playListMusic(title.title)' class="badge music-control">

Solution

  • $rootScope is an object so

    $rootScope.titleName = titleName;
    

    should do the trick.