0

I have the following code:

var myModule = angular.module('myModule', []);

myModule.controller('newController', ['$scope', function($scope) {
                   $scope.id = '1234';
}])
.component('myModalX', {
         templateUrl: `./partials/locationY?id=${$scope.id}`,
         controller: 'newController',
         controllerAs: 'vm'
});

This doesn't work. How can I ensure that I can pass $scope.id as part of the templateUrl?

Qwertiy
  • 19,681
  • 15
  • 61
  • 128
  • Does this answer your question? [Angular passing parameters through templateUrl in ui-router](https://stackoverflow.com/questions/34722102/angular-passing-parameters-through-templateurl-in-ui-router) – maverick Jan 16 '20 at 20:14
  • No, I'm using Symfony for my routing not ui-router. – Submissive Eagle Jan 17 '20 at 13:52

1 Answers1

0

Update: I figured out how to do it. I created a service that has a setter method that accepts the scope I need as a parameter, and a getter method that accesses the set variable in the service.

This way I'm able to access the variable in scope using the getter method in the service.

myModule.controller('newController', ['$scope', 'myScopeAcessingService', function($scope, myScopeAcessingService) {
                   $scope.id = '1234';
                   myScopeAcessingService.setValue($scope);

}])
.component('myModalX', {
         templateUrl: function(myScopeAcessingService) {

           const theIdIneed = myScopeAcessingService.getValue();

           return `./partials/locationY?id=${theIdIneed}`
         },
         controller: 'newController',
         controllerAs: 'vm'
});