Thursday, 15 August 2013

angularjs - angular directive data binding -


I am trying to write a simple angular command which displays an object property, but I do not understand That's how binding works.

  & lt; Div ng-repeat = "c in cars" & gt; & Lt; Div car carElement = {{c}} & gt; & Lt; / Div & gt; & Lt; Div & gt; . Directive ('car', function () {return} template: function (amm, attri) {var car = greater seat element; return car. Brand + '' + car model;}};});  

I can not force the hole object, just for the simple properties, for example, it works:

  & lt; Div ng-repeat = "c in cars" & gt; & Lt; Div car brand = {{c.brand}} & gt; & Lt; / Div & gt; & Lt; Div & gt; . Directive ('car', function () {return} {template: function (amm, atri) {var brand = atri.brand; return '' + brand;}};});  

How can I send the whole car to the instructional template?

You have to pass an object, but not inside the expression:

  & Lt; Div ng-repeat = "c in cars" & gt; & Lt; Div car carElement = "c" & gt; & Lt; / Div & gt; & Lt; Div & gt; Directive:  
 . Directive ('car', function () {returns: {car: "= cement"}, template: function (Elem, attr) {// now you have 'car' scope.car}};});  

No comments:

Post a Comment