I have, in my angular controller, a text like "For {{selDays}} days" which I want to bind to the view and have "selDays" changing.
I looked into $compile, but I saw that's mainly for use in directives.
Any ideas?
I have, in my angular controller, a text like "For {{selDays}} days" which I want to bind to the view and have "selDays" changing.
I looked into $compile, but I saw that's mainly for use in directives.
Any ideas?
$interpolate() can be used to interpolate the expression...
$scope.message = $interpolate("For {{selDays}} days")($scope);
But it'll only do it once. Use a watch if you need to reflect further changes to selDays...
var interpolatedMessage = $interpolate("For {{selDays}} days");
$scope.$watch('selDays', function () {
$scope.message = interpolatedMessage($scope);
});
Why don't you write "For {{selDays}} days" in your view. Then you write selDays var in the controller scope. Each time you will modifiy the variable, the display in the view will change (data binding)
ex.
VIEW: For {{selDays}} days
CONTROLLER: $scope.selDays = 42;