How can I change the $scope property value via the function in the $scope?
html,
<div ng-app="myApp" ng-controller="SimpleController">{{greeting}}</div>
angular,
var app = angular.module("myApp", []);
app.controller('SimpleController', function($scope) {
$scope.name = "World";
$scope.greeting = "Hi";
$scope.sayHello = function() {
return $scope.greeting = "Hello " + $scope.name;
};
});
Result,
Hi
What I expect,
Hello World
Or, can I add properties to $scope via function?
app.controller('SimpleController', function($scope) {
$scope.name = "World";
$scope.sayHello = function() {
return $scope.greeting = "Hello " + $scope.name;
};
});
html,
<div ng-app="myApp" ng-controller="SimpleController">{{greeting}}</div>
I get nothing...
Any ideas?
<div ng-app="myApp" ng-controller="SimpleController">{{sayHello(); greeting}}</div>?