Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display the property of an object in a directive?

The object looks like this:

{"objectId":"5666759200b09f85717e8954","name":"TestNewSunflower"...

The directive:

.directive('breadcrumb', function() {
            return {
                restrict: 'EA',
                template: '<ol class="breadcrumb">' +
                    '<li><a href="#/building/{{building.objectId}}">{{building}}</a></li>' +
                    '</ol>',
                scope: {
                    building: "@"

How I'm using it:

<breadcrumb building="{{building}}"></breadcrumb>

But I'm unable to display the name property.

I tried building.name, building[name] but nothing works.

What's the proper way of doing this?

like image 620
alexchenco Avatar asked Jan 23 '26 09:01

alexchenco


1 Answers

Using @ in scope, value will consider as text.

If you wanna use as an object,you have to parse with JSON.parse or angular.parse

Instead use building as two way.

Like this

building: "="

Then your html will be

<breadcrumb building="building"></breadcrumb>
like image 100
Anik Islam Abhi Avatar answered Jan 25 '26 22:01

Anik Islam Abhi



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!