[英]Issue with running Angular js
<!DOCTYPE html>
<html>
<head>
<title>ggl</title>
<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" href="css/style.css">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
</head>
<script src="js\angular.min.js"></script>
<script>
function Customer($scope){
$scope.CustomerName="bob";
$scope.CustomerCode="200";
}
var myApp = angular.module("myApp",[]);
myApp.controller("Customer", Customer);
</script>
<body>
<div id="CustScreen" ng-controller="Customer">
Customer Name :-<input ng-model="CustomerName"type="text" id="CustomerName">
Customer Code :-<input ng-model="CustomerCode"type="text" id="CustomerCode">
<div id="divCustomerName">{{CustomerName}}</div>
<div id="divCustomerName">{{CustomerCode}}</div><br/>
</div>
</body>
</html>
The outcome when I run the program is that it prints {{CustomerName}} in the div and not the expected input name. 运行该程序的结果是它在div中打印{{CustomerName}}而不是预期的输入名称。 I am unsure if it is a problem with the code itself or the linking I have made.
我不确定代码本身或我所做的链接是否有问题。
First of all, your script is between the <head>
and <body>
tag, but that's probably not the issue here. 首先,您的脚本位于
<head>
和<body>
标记之间,但这可能不是这里的问题。 The issue is most likely because you forgot to add 该问题最有可能是因为您忘记添加
ng-app="myApp"
on one of your root elements eg <html ng-app="myApp">
. 在您的一个根元素上,例如
<html ng-app="myApp">
。
Without that attribute, angular doesn't know where to start bootstrapping the application. 没有该属性,angular不知道从哪里开始引导应用程序。
You havent added ng-app directive in the HTML. 您尚未在HTML中添加ng-app指令。 Replace
<html>
as <html ng-app="myApp">
将
<html>
替换为<html ng-app="myApp">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.