This is my HTML right now, it has all the stuff in it, from the HTML itself, to the script:
<!doctype html>
<html lang="en-US" ng-app>
<!--Head-->
<head>
<meta charset="UTF-8">
<title>Lesson 5 - ng-show & ng-hide</title>
<meta name="viewport" content="width=device-width">
<style type="text/css">
* {
box-sizing: border-box;
}
body {
font: 16px/1.5 sans-serif;
color: #222;
margin: 5em;
}
</style>
</head>
<!--Body-->
<body ng-controller="information">
<div>
<label for="name">
Name:
<input type="text" name="username" id="username" placeholder="Your name here please" ng-model="name"/>
</label>
<br>
<label>
Hide?
<input type="checkbox" ng-model="checked"/>
</label>
</div>
<div ng-hide="checked">
Hidden Message here
<br>
Welcome {{ name || "user" }}!
</div>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
<script type="text/javascript">
var information = function ($scope) {
console.log($scope);
}
</script>
</body>
</html>
As you can see, this is a simple HTML page using AngularJS. You can see that the body is controlled by a controller called information
.
Now, the thing is, once you remove information, from the body tag, and place it into the first div
tag (as in place ng-controller="information"
into div tag instead of body tag), you will see that the program ceases to work (as in if you type in your name, it will not appear), and that is to be expected since the other div is outside the range of the controller.
Now, what I want to ask, is how do you access the data from another controller inside of your HTML? I've tried the following:
{{ information.name || "user" }}
<- First attempt{{ information.$scope.name || user }}
<- Second attempt, since {{}} evaluates JS
And in the end, I an not able to get my desired result. So, how can I access information from another scope into a div
tag that is independent of any scope?