为什么“;未定义的“;以棱角分明的js显示

why "undefined" show in angular js?

本文关键字:js 显示 未定义 为什么      更新时间:2023-09-26

我在console.log中没有定义。我正试图从我的视图中获取数据。你能告诉我为什么它没有显示模型数据吗。我会用来解释

我在登录.html文件中有这个

 <label class="item item-input">
                <span class="input-label">Username</span>
                <input type="text" ng-model="username">
            </label>

我想访问我的控制器中的用户名。控制器名称为authenticationCntrl

 function authenticationCntrl($scope,$state) {
        console.log('=====authenticationCntrl controller call')
         console.log($scope.username)
        console.log($scope.password)
         $scope.forgetPassword=function(){
            console.log($scope.username)
            console.log("dddd")
            console.log($scope.password)
        }

我填写了我的用户名和密码,当我点击"忘记密码"时,我得到了未定义的值,为什么?

这是我的代码http://goo.gl/Nte89L

单击预览检查输出

您遇到了.问题。来自本文:

有一个"。"在您的模型中将确保原型继承发挥作用。所以,使用

输入类型=";文本";ng模型=";someObj.prop1";而不是

输入类型=";文本";ng模型=";prop1";。

在控制器中定义一个容器对象:

$scope.obj = {};

在您的HTML:中

ng-model="obj.username"
ng-model="obj.password"