1

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?

4
  • 1
    Set an ng-controller='StateDetailsCtrl' on your html block and then you can call your scope variable with just {{testURL}} Commented May 9, 2014 at 6:19
  • What are you looking to do inside of those <script> tags? Commented May 9, 2014 at 6:21
  • I want to access the testURL variable set inside the controller. How to get this? Commented May 9, 2014 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. Commented May 9, 2014 at 6:32

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.