0

Below is a scratch of an application I'm working on:

<!doctype html>
<html ng-app>
    <head>
    <script src="/bower_components/angular/angular.js"></script>
        <script src="/bower_components/angular-youtube-mb/dist/angular-youtube-embed.min.js"></script>
        <script type="text/javascript">
            var myApp = angular.module('myApp', ['youtube-embed']);

            myApp.controller('MyCtrl', function ($scope) {
              // have a video id
              $scope.theBestVideo = 'i9MHigUZKEM';
            });
        </script>
    </head>
    <body ng-app="myApp">
        <div ng-controller="MyCtrl">
            <youtube-video video-id="theBestVideo"></youtube-video>
        </div>
    </body>
</html>

I can't find what is wrong, but I can see the Argument 'MyCtrl' is not a function, got undefined error in the chrome console. I think it's all there: the app, the controller, one bound to another. Can somebody point me out what is the problem here?

edit: in case it's relevant, I'm using 1.2.28 angular.js

2 Answers 2

2

A small mistake is there.
Change:<html ng-app>
To: <html ng-app="myApp">

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

4 Comments

yeah, right... this is how you end up using boilerplates... Btw, what is recommended - attaching ng-app to <html> or to <body> tag?
attaching ng-app to is better idea.
There is no big difference where you put ng-app. If you put it on <body> then you have a smaller scope for AngularJS which is slightly faster.
AngularJS will bootstrap the first ng-app it finds! That's it. If you have more than one ng-app, it will only process the first one. This why you are getting error.
1

I have verified your code,only thing you need to change is that remove this line

<html ng-app>

. Because you have used two html tags at beginning that's why you are getting error Argument 'MyCtrl' is not a function, got undefined.

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.