嘿大家想从网页发送值到另一个我试图使用一个服务,然后我又控制器,所以我可以从控制器将数据发送到另一个控制器,最后我想console.log
的结果,但没有什么是显示传递值从页面到另一个页面
这里是我的app.js
文件
//***********************************************************************************
var app=angular.module("siad",[]);
//***********************************************************************************
app.controller("siadController",['$scope','$http','dataShare','$location',function($scope,$http,dataShare,$location){
$http.get("/formulaire/all")
.success(function(data){
$scope.formulaire=data ;
});
$scope.send=function(){
//$scope.id=f.id_form;
//console.log(f)
/**$http.get("/question/form?idfrom="+f.id_form)
.success(function(data){
$scope.question=data;
console.log($scope.question)
})
**/
$scope.text = 'sssss';
$scope.send = function(){
dataShare.sendData($scope.text);
$location("/user/lesFormulaires.html")
}
}
}]);
//***********************************************************************************
app.controller("siadController2",['$scope','$http','dataShare',function($scope,$http,dataShare){
$http.get("/formulaire/all")
.success(function(data){
$scope.formulaire=data ;
});
$scope.text = '';
$scope.$on('data_shared',function(){
var text = dataShare.getData();
$scope.text = text;
console.log(text)
});
}]);
//***********************************************************************************
app.factory('dataShare',function($rootScope){
var service = {};
service.data = false;
service.sendData = function(data){
this.data = data;
$rootScope.$broadcast('data_shared');
};
service.getData = function(){
return this.data;
};
return service;
});
和这里的HTML按钮,当我点击我通过
<a href="/user/lesFormulaires.html" ng-click="send();" class="btn btn-large btn-primary black-btn">clickme</a>
重定向到另一个页面和发送数据
感谢所有帮助
你有changepageform()函数中你的send()函数作用域。也许试试把它分开放在changepageform()函数之外。 –
感谢提醒我,我忘了编辑它,我更新了问题,ps没有在控制台上显示 –