Reputation: 8240
<html>
<head>
<script src="angular.js"></script>
</head>
<body>
<div ng-app="myapp1">
<div ng-controller="cont1">
<h1>{{data.message}}</h1>
</div>
</div>
<script>
angular.module('myapp1', []).controller('cont1', function($scope){
$scope.data = "{message: 'Hello!'}";
});
</script>
</body>
</html>
I am passing values from a controller 'cont1' to the view of 'myapp1' module. I should see the result as "Hello!" on a html page, but I am getting pure blank white page. Can someone help me out?
Upvotes: 0
Views: 482
Reputation: 20633
Format your data correctly:
angular.module('myapp1', [])
.controller('cont1', function($scope){
$scope.data = {message: 'Hello!'};
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myapp1">
<div ng-controller="cont1">
<h1>{{data.message}}</h1>
</div>
</div>
Upvotes: 0
Reputation: 23811
All you are doing wrong is
$scope.data = "{message: 'Hello!'}";
should be
$scope.data = {message: 'Hello!'};
Here is a DEMO
Upvotes: 1
Reputation: 179
please don used ("") when you insert object to scope :).change like this:
$scope.data = {message: 'Hello!'};
Upvotes: 0