0

Here is working code PLUNKER in the controller

public JsonResult videohome()
        {
            BaseController bc = new BaseController();
            var video = (from n in bc.db.Video where n.Video == true select n).FirstOrDefault();
            var videos = new Videohome { youtubeid = "//www.youtube.com/embed/" + video.youtubeid };
            return Json(videos, JsonRequestBehavior.AllowGet);
        }
        public class Videohome
        {
            public string youtubeid { get; set; }
        }

It gives the ouptput as {"youtubeid":"//www.youtube.com/embed/_kux-YQujjM"}

But when i load this output into my script it displays error,

<script>

        countryApp.controller('Homevideo', ['$scope', "$http",'$sce', function (scope, sce, http) {
            http.get('@Url.Content("/sample/videohome")').success(function (data) {
                $scope.video = data;
                $scope.videoUrl = $sce.trustAsResourceUrl($scope.video + $scope.video.youtubeid);
             });
         }]);
</script>
        <div ng-controller="Homevideo" > <br />         
         <iframe width="100%" height="250" ng-src="{{videoUrl}}" frameborder="0" allowfullscreen=""></iframe>
            <p>{{videoUrl}}</p>       
          </div>

Did i missed anything in my code, Any help is appreciated.

1
  • you sure what you attached angular.js to your app ? Commented Jul 25, 2014 at 7:51

1 Answer 1

1

here is a working version (without the http): http://plnkr.co/edit/6M0qdSNlUe1f7mhT7ASt?p=preview I spotted few errors, first, try to organize the import in the same order and with a '$' prefix :

countryApp.controller('Homevideo', ['$scope', "$http",'$sce', function ($scope, $http, $sce)

The second thing I noticed is $scope.video + $scope.video.youtubeid I think you're not doing it right and $sce.trustAsResourceUrl($scope.video.youtubeid); should be enough as $scope.video is an json array it has nothing to do with the url.

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

1 Comment

Excellent, Thanks This code helps for my issue... :)

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.