为什么 "undefined" 显示在 angular js 中?
why "undefined" show in angular js?
我在控制台中未定义。log.I 我正在尝试从我的视图中获取数据。你能告诉我为什么它不显示模型数据吗?我将换句话说
我的 login.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)
}
我点击时填写了我的用户名和密码 "forget password" 我得到未定义的值 为什么?
这是我的代码
http://goo.gl/Nte89L
点击预览检查输出
您遇到了 .
问题。来自这篇文章 here:
Having a '.' in your models will ensure that prototypal inheritance is in play. So, use
input type="text" ng-model="someObj.prop1" rather than
input type="text" ng-model="prop1".
在你的控制器中定义一个容器对象:
$scope.obj = {};
在你的HTML中:
ng-model="obj.username"
ng-model="obj.password"
我在控制台中未定义。log.I 我正在尝试从我的视图中获取数据。你能告诉我为什么它不显示模型数据吗?我将换句话说
我的 login.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)
}
我点击时填写了我的用户名和密码 "forget password" 我得到未定义的值 为什么?
这是我的代码 http://goo.gl/Nte89L
点击预览检查输出
您遇到了 .
问题。来自这篇文章 here:
Having a '.' in your models will ensure that prototypal inheritance is in play. So, use
input type="text" ng-model="someObj.prop1" rather than
input type="text" ng-model="prop1".
在你的控制器中定义一个容器对象:
$scope.obj = {};
在你的HTML中:
ng-model="obj.username"
ng-model="obj.password"