Using AngularJS, I've noticed a pattern that seems wrong to me.
When building a table, my data is bound using ng-bind. But if I need the text in the cell to link to something, the link has to get created manually.
A non-linked table cell looks like:
<td ng-bind="customer.name"></td>
But if I want to create a link, I do:
<td><a ng-href="/customer/{{customer.id}}">{{customer.name}}</a></td>
Is there a way to create the link using attributes? Something like:
<td ng-bind="customer.name" ng-href="/customer/{customer.id}"></td>
The ng-href directive overrides the original href attribute of an <a> element. The ng-href directive should be used instead of href if you have AngularJS code inside the href value. The ng-href directive makes sure the link is not broken even if the user clicks the link before AngularJS has evaluated the code.
ng-bind directive binds the AngularJS Application data to HTML tags. ng-bind updates the model created by ng-model directive to be displayed in the html tag whenever user input something in the control or updates the html control's data when model data is updated by controller.
ngModel usually use for input tags for bind a variable that we can change variable from controller and html page but ngBind use for display a variable in html page and we can change variable just from controller and html just show variable.
href allows users to visit an external website from the current website. It is mostly used in anchor tags. Anchor tags are the most common HTML tags that take href as a parameter and route users to another website. In Angular, developers should use ng-href instead of href in the anchor tags.
This isn't really an AngularJS issue; this is more about how HTML works. HTML doesn't allow you to just add an href
attribute to any element to create a link. You need to use the anchor tag to create a link.
If you want, you could write a directive that produces the anchor tag inside cells. But that hardly seems worth it, and most would probably agree that it produces less semantic, more confusing markup.
HTML links spec: http://www.w3.org/TR/html4/struct/links.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With