Monday, February 26, 2024
 Popular · Latest · Hot · Upcoming
135
rated 0 times [  137] [ 2]  / answers: 1 / hits: 8909  / 9 Years ago, sat, january 3, 2015, 12:00:00

Here's a directive I created:



HTML:



<p-test something='bla'></p-test>


JavaScript:



.directive('pTest', function() {
return {
scope: {
something: '=?'
},
templateUrl: 'components/testTemplate.html',
controller: 'testController'
};
});


I'd like to be able to pass 'bla' as a string without the '', in the following way:



<p-test something=bla></p-test>


I know it's possible via the attributes parameter in link, but it's irrelevant in this case (correct me if I'm wrong) as I'm passing these parameters directly to scope.


More From » angularjs

 Answers
2

I'd like to be able to pass 'bla' as a string without the '', in the following way:




You would just need text binding (@) binding for that, instead of 2 way binding.



.directive('pTest', function() {
return {
scope: {
something: '@?' //<-- Here
},
templateUrl: 'components/testTemplate.html',
controller: 'testController'
};
});


and with the text binding if you want to bind scope properties then use interpolation. i.e example if bla is a scope variable holding a string then just do:



 <p-test something={{bla}}></p-test>


Plnkr


[#40263] Friday, January 2, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ansleyk

Total Points: 42
Total Questions: 100
Total Answers: 83

Location: Angola
Member since Wed, Apr 13, 2022
2 Years ago
;