Javascript 在Ionic中获取了未定义的输入值
我只是想在控制器中得到我的输入值。但我的网页上总是有一个“未定义的” 这是我的HTML代码Javascript 在Ionic中获取了未定义的输入值,javascript,angularjs,ionic-framework,ionic,Javascript,Angularjs,Ionic Framework,Ionic,我只是想在控制器中得到我的输入值。但我的网页上总是有一个“未定义的” 这是我的HTML代码 <div class="list"> <label class="item item-input"> <input id="FirstName" type="text" placeholder="* First Name" data-ng-model="Info.FirstName" /> </label&g
<div class="list">
<label class="item item-input">
<input id="FirstName" type="text" placeholder="* First Name" data-ng-model="Info.FirstName" />
</label>
</div>
当我单击按钮Next()时,它将运行并警告“未定义”。这是一个非常简单的函数。我想这是因为我使用了离子框架。你想实现这个吗 HTML
<!DOCTYPE html>
<html ng-app="plunker">
<head>
<meta charset="utf-8" />
<title>AngularJS Plunker</title>
<script>document.write('<base href="' + document.location + '" />');</script>
<link rel="stylesheet" href="style.css" />
<script data-require="angular.js@1.3.x" src="https://code.angularjs.org/1.3.15/angular.js" data-semver="1.3.15"></script>
<script src="app.js"></script>
</head>
<body ng-controller="MainCtrl">
<div class="list">
<label class="item item-input">
<input id="FirstName" type="text" placeholder="* First Name" ng-model="Info.FirstName" />
</label>
<button ng-click="Next(Info)"> Next </button>
{{value}}
</div>
</body>
</html>
Plnkr:参见我的示例:
<div class="item item-body">
<form style="" class="list">
<label class="item item-input item-floating-label">
<span class="input-label">Enter file content</span>
<input type="text" ng-model="file.input" placeholder="Enter file content">
</label>
</form>
<div style="" class="button-bar">
<button class="button button-positive button-block button-outline" id="write_file" ng-click="wirteFileContent(file)">Write</button>
<button class="button button-positive button-block button-outline" id="read_file" ng-click="readFileContent()">Read</button>
</div>
</div>
输入文件内容
写
阅读
请记住:ng model=“文件”输入“。。。。。。。ng click=“wirteFileContent(文件)”
在控制器中:
$scope.wirteFileContent=函数(文件){
console.log(file.input);
};代码>不,你搞乱了控制器层次结构,你没有维护它我没有在这里复制我的所有代码,我确信我的控制器是正确的。是的,我想你的代码会工作的。由于几天前无法修复错误,我更改了代码,将所有内容放在一个页面中(之前,我尝试将每个输入元素中的值保存到一个角度对象)。现在我的应用程序运行良好。谢谢:)
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.Next = function (infodata) {
$scope.value=infodata;
};
});
<div class="item item-body">
<form style="" class="list">
<label class="item item-input item-floating-label">
<span class="input-label">Enter file content</span>
<input type="text" ng-model="file.input" placeholder="Enter file content">
</label>
</form>
<div style="" class="button-bar">
<button class="button button-positive button-block button-outline" id="write_file" ng-click="wirteFileContent(file)">Write</button>
<button class="button button-positive button-block button-outline" id="read_file" ng-click="readFileContent()">Read</button>
</div>
</div>