什么是&QUOT事业;角没有定义"

问题描述:

我下面就 egghead.io 视频教程,但试图以他为榜样,当他创造了一个工厂(详见视频here)我不断收到角没有定义引用错误,但我已经包括角脚本

I'm following the video tutorials on egghead.io but while trying to follow his example when he created a factory (see video here) I keep getting "angular is not defined" Reference Error but I have included the angular script

这是我的html页面:

This is my html page:

<!DOCTYPE html>
<html>
    <head>
    <title>Prototype</title>
    <link rel="stylesheet" type="text/css" href="foundation.min.css">
    <script type="text/javascript" src="main.js"></script>
    </head>
    <body>

    <div data-ng-app="">

        <div data-ng-controller="FirstController">
            <input type="text" data-ng-model="data.message">
            <h1>{{ data.message }}</h1>
        </div>



        <div data-ng-controller="SecondController">
            <input type="text" data-ng-model="data.message">
            <h1>{{ data.message }}</h1>
        </div>


    </div>
    <script type="text/javascript" src="angular.min.js"></script>
    </body>
</html>

这就是我的JavaScript文件main.js

and this is my javascript file "main.js":

//Services
    // step 1 create an app                             
    var myApp = angular.module('Data', []).
    // tep 2 create factory
                // Service name, function
    myApp.factory('Data', function(){
        return { message: "I'm Data from a Service" }
    });



//Controllers
    function FirstController($scope, Data){
        $scope.data = Data;
    }

    function SecondController($scope){

    }

我看了几个帖子有类似发生(here)并请纠正我,如果我错了,但我认为这是引导捆扎安迪手动尝试使用 angular.bootstrap(文件,['数据'])自举办; 但没有成功,仍然得到同样的错误。

I have read a few posts where similar happen (here) and please correct me if I'm wrong but I think it is to do with Boot strapping andI have tried manually bootstrapping using angular.bootstrap(document, ['Data']); but with no success, still get same error.

但我想知道的是,为什么这个网上适用于这样的例子很多,像理论家系列影片,但我有问题,因为我相信我按照他的视频十分密切。它是在最新版本的角度的变化?

But What I want to know is, Why this works for so many examples online, like the egghead video series, but I have issues as I believe I have followed his video very closely. is it a change in angular in recent versions?

您必须把你的脚本标记引用角一前一后。将它移出

You have to put your script tag after the one that references Angular. Move it out of the head:

<script type="text/javascript" src="angular.min.js"></script>
<script type="text/javascript" src="main.js"></script>

您已经设定,现在的方式,角加载页面之前你的脚本运行。

The way you've set it up now, your script runs before Angular is loaded on the page.