Reputation: 49
I put data in the ng-init then I want to receive these value for my controller.
<div ng-controller='hotelDetailCtrl' data-ng-init="mytest='hello'" class="col-sm-9 col-lg-9" >
app.controller('hotelDetailCtrl', function ($scope, $http) {
$scope.init = function(){
alert($scope.mytest);
};
});
But I can't get these value from my controller.Please help me and then explain about these case.
Upvotes: 0
Views: 1751
Reputation: 506
You are trying to call init function inside your controller, but haven't called it inside your code, I assume this is what you planned to do:
var app = angular.module('myapp', []);
app.controller('hotelDetailCtrl', function ($scope, $http) {
$scope.init = function(){
alert($scope.mytest);
};
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="myapp">
<div ng-controller='hotelDetailCtrl' data-ng-init="mytest='hello'; init();" class="col-sm-9 col-lg-9" >
</div>
</body>
Upvotes: 1