显示引用了 Ng-Model 的输入值
Display input value with Ng-Model referenced
我知道在引用 Ng-Nodel 时我无法设置输入的值,但我正在尝试寻找解决方法。
正在从用户在上一页中输入的 URL 变量(例如全名或电子邮件)中提取 html 值。 Ng-model 被用来存储这些信息。 - signUp.php?user_email=$email&fname=$fullNam
下面是我的意思的一个例子,
<?php
$email = $_GET['user_email'];
$fullName = $_GET['fname'];
?>
<input id="signupformItem" ng-model="user.username" type="email" name="email" value= <?php echo $email; ?> placeholder="Email Address" required> <br>
如有任何帮助,我们将不胜感激
我刚刚为您创建了一个演示,但我会建议您完成一些系列教程,以更好地了解您要使用的框架或技术(angularjs 和 javascript)在您的项目中使用。
我为你创建了 plunk。你可以去看看here.
Javascript代码
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope, userService) {
$scope.name = 'World';
$scope.userName = userService.getUsers();
userService.getUserAjax()
.success(function(response) {$scope.names = response[0].Name;});
});
app.service('userService', function($http){
var fac = {};
fac.getUserAjax = function() {
return $http.get("http://www.w3schools.com//website/Customers_JSON.php");
};
fac.getUsers = function(){ return 'John'};
return fac;
});
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.13/angular.js" data-semver="1.3.13"></script>
<script src="app.js"></script>
</head>
<body ng-controller="MainCtrl">
<p>Hello {{name}}!</p>
by {{userName}}
<p>username loaded by ajax :{{names}}</p>
</body>
</html>
您需要使用 angular ($http
) 提供的 ajax 服务定义一项与您的网页通信的服务,并从控制器和成功函数调用它获取值并将其分配给您的范围变量。在你的情况下用户名。
我只是在这里使用 w3schools 服务 url 只是为了演示,它会给我一个用户列表,你需要实现 php 代码,return 你想要什么并使用它如上所述。
我希望它能让您了解如何设置 angular 代码与服务器通信的基本概念。
我知道在引用 Ng-Nodel 时我无法设置输入的值,但我正在尝试寻找解决方法。
正在从用户在上一页中输入的 URL 变量(例如全名或电子邮件)中提取 html 值。 Ng-model 被用来存储这些信息。 - signUp.php?user_email=$email&fname=$fullNam
下面是我的意思的一个例子,
<?php
$email = $_GET['user_email'];
$fullName = $_GET['fname'];
?>
<input id="signupformItem" ng-model="user.username" type="email" name="email" value= <?php echo $email; ?> placeholder="Email Address" required> <br>
如有任何帮助,我们将不胜感激
我刚刚为您创建了一个演示,但我会建议您完成一些系列教程,以更好地了解您要使用的框架或技术(angularjs 和 javascript)在您的项目中使用。
我为你创建了 plunk。你可以去看看here.
Javascript代码
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope, userService) {
$scope.name = 'World';
$scope.userName = userService.getUsers();
userService.getUserAjax()
.success(function(response) {$scope.names = response[0].Name;});
});
app.service('userService', function($http){
var fac = {};
fac.getUserAjax = function() {
return $http.get("http://www.w3schools.com//website/Customers_JSON.php");
};
fac.getUsers = function(){ return 'John'};
return fac;
});
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.13/angular.js" data-semver="1.3.13"></script>
<script src="app.js"></script>
</head>
<body ng-controller="MainCtrl">
<p>Hello {{name}}!</p>
by {{userName}}
<p>username loaded by ajax :{{names}}</p>
</body>
</html>
您需要使用 angular ($http
) 提供的 ajax 服务定义一项与您的网页通信的服务,并从控制器和成功函数调用它获取值并将其分配给您的范围变量。在你的情况下用户名。
我只是在这里使用 w3schools 服务 url 只是为了演示,它会给我一个用户列表,你需要实现 php 代码,return 你想要什么并使用它如上所述。
我希望它能让您了解如何设置 angular 代码与服务器通信的基本概念。