JSFiddle - React, Tailwind, and code Playground
by dshilkret
HTML
<!DOCTYPE html>
<html lang="en" ng-app="myApp">
<head>
<meta charset="UTF-8">
<title>AngularJS Example</title>
</head>
<body ng-controller="myController">
<div ng-repeat="item in items">
<a class='gotoLine' ng-href="{{generateHref(item)}}">{{generateHref(item)}}</a>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>
<script src="app.js"></script>
</body>
</html>
JavaScript
var app = angular.module('myApp', []);
app.controller('myController', function($scope) {
$scope.items = [
{ line: 1, content: 'Line 1 content' },
{ line: 2, content: 'Line 2 content' },
{ line: 3, content: 'Line 3 content' },
{ line: 4, content: 'Line 4 content' },
{ line: 5, content: 'Line 5 content' }
];
$scope.generateHref = function(item) {
try {
if (!item || !item.line) {
throw new Error('Invalid item');
}
return '#line' + item.line;
} catch (error) {
console.error('Error generating href:', error);
return '#error';
}
};
});