1
I have this:
$scope.products = [];
$http.get('app/components/job/controller/teste.json').success(function (resource) {
$scope.products = resource;
});
$scope.getIdJobs = function(getIdJobs) {
var result = $filter('filter')( $scope.products, {id:getIdJobs})[0];
console.log(result);
console.log(getIdJobs);
}
I wanted my second controller to get the $Scope.getIdJobs variable and store it in a variable again. How can I do that?
app.controller("job_detail", ["$scope", "$http", "$location", "$route","$rootScope", "$routeParams", function($scope, $http, $location, $route, $rootScope, $routeParams) {
//image home
$rootScope.home = false;
//change color background in page job
$scope.isOnCertainPage = function() {
return $location.path() === "/job";
};
$http.get('app/components/job/controller/teste.json').success(function (resource) {
$scope.products = resource;
$scope.jobId = $routeParams.jobId;
//console.log($scope.jobId);
});
console.log($scope.title, $scope.localidade, $scope.products);
}]);
app js.
app.config(function($routeProvider, RestangularProvider){
$routeProvider
.when("/",{
templateUrl: "app/components/home/views/job_offers.html",
controller: "employerCtrl"
})
.when("/job" , {
templateUrl: "app/components/job/views/job.html",
controller: "job"
})
.when("/job/:jobId" , {
templateUrl: "app/components/job/views/jobdetail.html",
controller: "job_detail"
})
.otherwise({
redirectTo: '/'
});
});
See help: http://stackoverflow.com/questions/12008908/angularjs-how-can-i-pass-variables-between-controllers
– Miguel
is a good example but as I am using parameters on different pages it gets lost in the middle
– Jose Cerejo
What do you mean? Your question was to share a variable between controllers, so there’s more going on? If yes, change your question and add this information.
– Filipe Moraes
I’ve already changed the content
– Jose Cerejo
I still can’t figure out what it is. Looking at the link @Miguel shared and your question, it solves the problem. What do you understand in your code as a parameter? Where is this parameter?
– Filipe Moraes
I consider a parameter for example in my app.js. I have job and job/:id and when going to the id page goes with a parameter. I want the information I upload to any topic to go to the corresponding page of that ID
– Jose Cerejo
So in your controller
job_detail
you can capture the ID (jobId) and use it on your controller. This would not be intended?– Filipe Moraes
I’ve already managed to get the controller to send the information to another controller with the example of Miguel. I’m using an Angularjs ng-click technology when you press the button it stores in a variable. It is possible that this variable when it loads guardes in the variable I created now to send to the 2 controller?
– Jose Cerejo
Read my answer on that question: http://answall.com/questions/164782/passar-valor-para-service-factory-em-angularjs
– celsomtrindade
Have you ever thought of using ui-router to control the page exchange and so receive parameters through the URL?
– Sorack