ng-click 函数参数作为 $scope 变量 angular 1.x

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

我想将通过 ng-click 获得的参数用作 $scope 变量,以便在我网站的任何地方使用它。

我的控制器:

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();
  }
//...
});

我的 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">

$rootScope 是一个对象所以

$rootScope.titleName = titleName;

应该可以解决问题。