我知道这已经发布之前,但我仍然困惑如何实现这个我的具体问题。AngularJS - 在控制器之间共享变量
我的第一个控制器:
myApp.controller("buttonCtrl", function($scope){
$scope.johnny = [
{quote: "Anything for My Princess", controller: Princess},
{quote: "Don't Even Ask", controller: DontAsk}];
}
现在我想用$ scope.johnny对象在此控制器:
function Princess($scope){
$scope.play = function(){
//use $scope.johnny.quote or something of the sorts in here
}
}
这将如何做呢?我看过使用$ rootScope或服务的帖子;然而,我将如何执行一个在我的情况。
非常感谢。
@Beterraba是的,我相信它是,但我仍然不确定如何做到这一点。谢谢 – benjipelletier