Himmators
Himmators

Reputation: 15006

Default value if no value is in the scope?

Retreiveing a value like {{cat}} from angular, is there a way to set a value that will output if no value is in the $scope?

Upvotes: 0

Views: 63

Answers (2)

Oleg Haidul
Oleg Haidul

Reputation: 3732

Also u can use

$scope.cat ||= "Tom Cat"

in your controller.

Upvotes: 0

AlwaysALearner
AlwaysALearner

Reputation: 43947

Not sure if you want to do something like this:

<div ng-init="cat = cat || 'Tom Cat'">{{cat}}</div>

If you are not looking to initialize but just want to display it:

<div>{{cat || "Tom Cat"}}</div>

Upvotes: 5

Related Questions