我正在使用 Angular 框架并尝试将 $scope 传递到我的应用程序中的不同 Controller 。
更新:
我的问题是在用户单击按钮之前我无法获取 $scope 数据。
.controller('firstCtrl', function($scope) {
$scope.getTest = function(){
$scope.test1 = 'good.'
$scope.test2 = 'bad.'
…..more
}
})
我需要将 $scope 对象传递给不同的 Controller
.controller('secondCtrl', function($scope) {
console.log($scope.test1)
})
我该怎么做?谢谢!
最佳答案
为了在两个 Controller 之间共享数据,您需要使用 factory 。
有关更多详细信息,请观看此视频:“AngularJS Video Tutorial: Sharing Data Between Controllers”,作者:John Lindquist。
关于javascript - 如何在 Angular js 中将值传递给不同的 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22701497/