0

Hi I have a controller variable

         $scope.submitQuestion = function(){
         $scope.post.createdTime = createdtime;
         $scope.post.creator = $scope.user.profile.username;
         $scope.post.creatorUID = $scope.user.uid;
           $scope.post.creatorpic = $scope.user.profile.userpic;
        $scope.post.postmedia = $scope.object.video.info.uuid;
        $scope.post.postmediaimage = $scope.object.image.info.uuid;
       Post.create($scope.post).then  (function(ref) {

    $location.path('/posts/' + ref.name());

     });

     };

And this is my view I am planning to use

         <body>
       <div id="player"></div>
         <script>
          var player = new Clappr.Player({source: 
             {{post.postmedia}} , parentId: "#player"});
        </script>
        </body>

Is it possible to pass my scope variable $scope.post.postmedia to the script tag ?

4
  • Yes, have a look at this post stackoverflow.com/questions/14237551/… Commented Jul 18, 2015 at 14:49
  • Karthik – try to explain why controller is not enough good place for creating new objects and you want to do this in the view. Commented Jul 18, 2015 at 15:23
  • Krzysztof I did try to use the controller but the script binds to player div , I am new to angular and am not sure how to bind the player variable to div id - 'player' in the controller. Commented Jul 18, 2015 at 15:29
  • I did try this to pass object from controller var player = new Clappr.Player({source: $scope.post.postmedia , parentId: "#player"}); Commented Jul 18, 2015 at 15:52

1 Answer 1

0

Yes there is another way to use $window service. Its equal to javascript's window object. You should assign a attribute to window object first and use this global variable value from anywhere in your multiple js files.

You should inject $window service first in your controller. Your controller declaration will look like

angular.controller('MyController', ['$scope', '$window', function ($scope, $window){
    $window.post.postmedia = $scope.object.video.info.uuid; // Assign value first
}])

Now you can use this attribute value from everywhere. Like

<script>
     var player = new Clappr.Player({source: 
     post.postmedia , parentId: "#player"}); //post.postmedia will work if it will have been assigned first else it will show undefined
</script>
Sign up to request clarification or add additional context in comments.

3 Comments

Hi Vineet thanks for the reply .. I did try it and got post undefined error !
try window.post.postmedia in script tag
Willl you please create fiddle so I can check myself ?

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.