为什么我的AngularJS模块不会装载? [英] Why is my AngularJS module never loaded?

查看:173
本文介绍了为什么我的AngularJS模块不会装载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个新手AngularJS,和我有困难得到一个AngularJS形式才能正常工作。 Chrome开发工具告诉我,我的模块没有被加载。

I am an AngularJS newbie, and am having difficulty getting an AngularJS form to work correctly. Chrome Dev Tools tells me my module is not being loaded.

下面是我的HTML;它是一个字preSS模板中的div:

Below is my html; it is a div within a Wordpress template:

<div ng-app="contact" style="float: left;">
    <form method="post" name="form" role="form" ng-controller="ContactFormController" ng-submit="form.$valid && sendMessage(input)" novalidate>
    <p ng-show="success">Thanks for getting in touch!</p>
    <p ng-show="error">Something wrong happened!, please try again.</p>
    <legend>Contact</legend>
    <fieldset>
    <div>
      <label for="name">Name:</label>
      <input type="text" id="name" name="name" ng-model="input.name" required>
    </div>
    <div>
        <label for="email">Email:</label>
        <input type="email" id="email" name="email" ng-model="input.email" required>
    </div>
    <div>
        <label for="messsage">Message:</label>
        <textarea id="messsage" name="message" ng-model="input.message" required></textarea>
    </div>
    <div>
        <label for="honeypot">I promise I'm not a bot</label>
        <input type="text" id="honeypot" name="honeypot" ng-model="input.honeyPot">
    </div>
    </fieldset>
    <button type="submit" name="submit" value="submit">Submit</button>
    </form>
    </div>

这是我的角度code:

This is my angular code:

angular.module("contact", [])
    .controller("ContactFormController", ['$scope', '$http', function($scope, $http) {
    $scope.success = false;
    $scope.error = false;

    $scope.sendMessage = function( input ) {
        $http({
            method: 'POST',
            url: 'http://alamanceforeducation.org/wp-content/themes/flex/library/scripts/processApplecartForm.php',
            data: input,
            headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
        })
            .success( function(data) {
                if ( data.success ) {
                    $scope.success = true;
                } else {
                    $scope.error = true;
                }
            } );
    }
}]);

在code是改编自一个教程。谁能帮我出什么我做错了?

The code is adapted from a tutorial. Can anyone help me out with what I am doing wrong?

推荐答案

有什么不对您的code你所遇到的问题的条款。问题是您在其中加载脚本的顺序。

There's nothing wrong with your code in terms of the problem you are having. The problem is the order in which you are loading the scripts.

的顺序应该是:
1 angular.js
2 - 任意角dependency.js
3 您-角app.js

这是你的code 的工作副本
我不包括形式,因为只是为了告诉你,它没有找到你的角模块,因为无论你是不包括它或没有从CDN正确加载,则可能需要下载它有它在本地,并包括&LT;脚本SRC =angular.js&GT;&LT; / SCRIPT&GT; 标签

这篇关于为什么我的AngularJS模块不会装载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆