Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am new to AngularJs. I have put a url value in the scope variable inside a controller. This value should be used in the partial file corresponding to the controller inside a javascript function. How can I achieve this in AngularJs.

Code snippet is given below for reference: Config code:

myApp.config(function ($routeProvider){
  $routeProvider.
   when('/state-details/:id',
   {
      controller:'controllers.StateDetailsCtrl',
      templateUrl:'/partials/state-details.html'
   })
   .... More routes defined below...

Inside the controller:

controllers.StateDetailsCtrl= function($scope, $routeParams, $http){
  $scope.testURL='http://www.google.com'
  .... More values set in the scope..

Inside the state-details partial file:

<script>
// how to get the value of the testURL defined in the scope?
</script>

Please let me know how to get this working?

share|improve this question
1  
Set an ng-controller='StateDetailsCtrl' on your html block and then you can call your scope variable with just {{testURL}} –  Tim Castelijns May 9 at 6:19
    
What are you looking to do inside of those <script> tags? –  Marc Kline May 9 at 6:21
    
I want to access the testURL variable set inside the controller. How to get this? –  Pradeep May 9 at 6:31
1  
If i add the ng-controller='StateDetailsCtrl' inside the html block and try to access the testURL inside the script tag I am getting an error. –  Pradeep May 9 at 6:32

1 Answer 1

If you need to add additional javascript into a partial html file, then it just like screams to use a directive.

There you can inherit the whole ctrl scope or create a isolated scope.

https://docs.angularjs.org/guide/directive

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.