Onsen [ng:areq] Argument''不是函数,未定义

时间:2016-04-12 21:03:01

标签: javascript angularjs twitter-bootstrap onsen-ui monaca

我知道这个问题被问了大约一百次。我尝试了很多解决方案。可悲的是,没有人为我工作。

我正在使用Onsen和AngularJS进行编程。

HTML:

    <ons-template id="signin.html">
    <ons-dialog var="dialog">            
        <ons-toolbar>
            <div class="center">Log In</div>
        </ons-toolbar>

        <div class="login-form" ng-app="SignIn" ng-controller="SignCtrl">
            <input type="email" class="text-input--underbar" placeholder="Email" value="">
            <input type="password" class="text-input--underbar" placeholder="Password" value="">
            <br><br>
            <ons-button modifier="large" class="login-button">Log In</ons-button>
            <br>
            <ons-button modifier="quiet" class="forgot-password">Forgot password?</ons-button>
            <ons-button modifier="quiet" class="forgot-password" ng-click="showSignUp()">Not a member?</ons-button>
        </div>

    </ons-dialog>
</ons-template>

Javascipt(js / signctrl.js):

(function(angular){
    // init functions
    'use strict';

    var app = angular.module('SignIn', []);
    app.controller('SignCtrl', function($scope) {
        $scope.showSignUp = function() {       
            alert("foo!");
            ons.createDialog('signup.html').then(function(dialog) { dialog.show(); });
        };
    });

})(window.angular);

包含文件:

<script src="components/loader.js"></script>
<link rel="stylesheet" href="components/loader.css">
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/signin.css">
<link rel="stylesheet" href="css/signup.css">
<link rel="stylesheet" href="css/locations.css">

<link rel="stylesheet" href="lib/onsen/css/onsenui.css">
<link rel="stylesheet" href="components/monaca-onsenui/css/onsen-css-components-sunshine-theme.css">
<script src="lib/onsen/js/angular/angular.js"></script>
<script src="lib/onsen/js/onsenui.js"></script>
<script src="js/signctrl.js"></script>

在开头调用ons.bootstrap()(在包含js / signctrl.js之前)。

如果你能帮助我并感谢你的帮助,我将非常高兴。

PS:完整错误为[ng:areq] Argument 'SignCtrl' is not a function, got undefined

PPS:真正的完整错误:

Error: [ng:areq] Argument 'SignCtrl' is not a function, got undefined
http://errors.angularjs.org/1.4.3/ng/areq?p0=SignCtrl&p1=not%20a%20function%2C%20got%20undefined
    at file:///data/data/mobi.monaca.debugger/files/projects/cloud/570c898afd17349b6c3d57a4/www/components/loader.js:1460:4931
    at assertArg (file:///data/data/mobi.monaca.debugger/files/projects/cloud/570c898afd17349b6c3d57a4/www/components/loader.js:1460:18360)
    at assertArgFn (file:///data/data/mobi.monaca.debugger/files/projects/cloud/570c898afd17349b6c3d57a4/www/components/loader.js:1460:18562)
    at file:///data/data/mobi.monaca.debugger/files/projects/cloud/570c898afd17349b6c3d57a4/www/components/loader.js:1462:20613
    at setupControllers (file:///data/data/mobi.monaca.debugger/files/projects/cloud/570c898afd17349b6c3d57a4/www/components/loader.js:1461:27741)
    at nodeLinkFn (file:///data/data/mobi.monaca.debugger/files/projects/cloud/570c898afd17349b6c3d57a4/www/components/loader.js:1461:28989)
    at compositeLinkFn (file:///data/data/mobi.monaca.debugger/files/projects/cloud/570c898afd17349b6c3d57a4/www/components/loader.js:1461:21271)
    at file:///data/data/mobi.monaca.debugger/files/projects/cloud/570c898afd17349b6c3d57a4/www/components/loader.js:1461:19821
    at pre (file:///data/data/mobi.monaca.debugger/files/projects/cloud/570c898afd17349b6c3d57a4/www/components/loader.js:1474:25379)
    at invokeLinkFn (file:///data/data/mobi.monaca.debugger/files/projects/cloud/570c898afd17349b6c3d57a4/www/components/loader.js:1462:13182)

1 个答案:

答案 0 :(得分:1)

这可能是一个时间问题。在初始化包含控制器的元素之前,它尝试访问控制器。 要解决此问题,请将角度代码包装在ons.ready函数(see the docs)上,该函数将在onsen完全加载后执行代码。

例如:

ons.ready(function() {

  //Your angular code

})

此外,您似乎忘了将温度模块添加到控制器中。

希望它能解决你的问题!