1

我正在使用 monaca ide 进行开发。

我正在尝试使用 angularjs 将数据从 html 发布到 php 页面,这给了我错误 Uncaught Error: [ng:areq] Argument 'joinctrl' is not a function, got undefined我对 angularjs 一无所知,请帮忙我有这个,谢谢你的帮助。

html

索引.html

<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1, maximum-scale=1, user-scalable=no">
    <script src="components/loader.js"></script>
    <script src="js/script.js"></script>
    <link rel="stylesheet" href="components/loader.css">
    <link rel="stylesheet" href="css/style.css">
    <script>
        ons.bootstrap();
        ons.disableAutoStatusBarFill();  // (Monaca enables StatusBar plugin by default)
    </script>
</head>
<body>
    <ons-navigator title="Navigator" var="myNavigator" page="page1.html">

    </ons-navigator> 
</body>
</html>

page2.html

<ons-page style="background:#5C2D50">
<div class="modal">
    <div class="modal__content" ng-app=joinus ng-controller="joinctrl">
        <form>
        <h1>Join Us</h1>
        <input type="email" placeholder="Email" ng-model="email"><br />
        <input type="password"  placeholder="Password" ng-model="password"><br />
        <input type="password"  placeholder="Confirm Password" ng-model="cpassword"><br />
        <input type="submit" value="Create" class="creat" ng-submit="create()">
        </form>
    </div>
</div>
<div id="gos" onclick="myNavigator.popPage()"><span class="fa fa-chevron-left" id="bk"></span></div>
</ons-page>

脚本.js

var app = angular.module('joinus', ['onsen']);

app.controller('joinctrl', function($scope, $http){
   $scope.create=function(){
       var request=$http({
           method:"post",
           url:"http://www.elunika.com/joinus.php",
           data:{
               email:$scope.email,
               password:$scope.password,
               cpassword:$scope.cpassword
           },
           headers:{'Content-Type':'application/x-www-form-urlencoded'}
       });
   request.success(function(data){
       myNavigator.popPage();
   });
   request.error(function(data){
       alert("Error While Proccessing");
   })
   }
});

请让我知道我正在做的错误。

  1. 如果我使用 angularjs ,请告诉我是否<form>需要在 html 中使用。
  2. 请让我知道我是否可以使用alert我们在 jquery 中使用的相同方式。

再次感谢您的帮助。

4

2 回答 2

1

您的文件onsen中是否包含模块依赖项index.html

这是您的代码的工作版本onsen,已排除。

ng-app可以在<html>or<body>标记处使用单个。ng-app确保在整个应用程序中具有单一属性。

至于:

  1. 你可以<form>这样使用。

  2. 你可以。

:)

PS:我提供的 Plunker 示例没有出现 的问题areq,正如您在浏览器的控制台中看到的那样。

于 2014-11-22T20:17:16.317 回答
0
  1. 使用 AngularJS 时确实需要使用表单。这与其他框架的方式相同。您将 ng-click 添加到提交按钮的方式是有效的。
  2. AngularJS 只是一个 JavaScript 框架。您使用警报的方式是有效的。

请问您在什么时候/在什么时候得到Uncaught Error: [ng:areq] Argument 'joinctrl' is not a function, got undefined

于 2014-11-22T20:15:14.763 回答