Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS: Bind attribute value from controller function

My markup was:

<input char-limit="10" />

Then I needed to set the attribute value from controller, so I did this:

 <input char-limit="{{charLimit}}" />

And in controller:

$scope.charLimit = <my value>;

Now, instead of using the model value directly; I need to use the function to return the value. So I did:

<input char-limit="getCharLimit()" />

And in controller:

$scope.getCharLimit= function(){
    return <my value>;
}

But the value is not reflected in the markup.

like image 943
benjamin54 Avatar asked Oct 27 '25 17:10

benjamin54


2 Answers

You need to enclose the function inside of curly braces

<input char-limit="{{getCharLimit()}}" />
like image 191
Bidhan Avatar answered Oct 30 '25 06:10

Bidhan


Typically an Angular Expression must be enclosed within {{ }}

{{ expression }}

So the correct one should be : <input char-limit="{{getCharLimit()}}" />

like image 39
Dinesh Chitlangia Avatar answered Oct 30 '25 07:10

Dinesh Chitlangia



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!