Learning angular.js and have this simple code but don't understand how to change the value of the "name" variable in the controller.
HTML:
<!DOCTYPE html>
<html lang="en" ng-app ng-controller="AppCtrl">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script>
<script src="../js/controller.js"></script>
</head>
<body>
<h1>Hello, {{name}}</h1>
<input type="text" ng-model="name">
</body>
</html>
Controller.js code is as followed:
function AppCtrl($scope){
$scope.name = "World";
}
Before I added the controller the <h1>
tag dynamically changed depending on what was typed in the input field. But when the controller was added the value of the H1
tag is always:
" Hello, {{name}}" (this is what is shown in the browser character by character)
Can anyone explain why and also how to change the value of the 'H1` tag using a controller method?