JSFiddle - React, Tailwind, and code Playground
by Sid Sah
HTML
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular.min.js"></script>
<div ng-app="app">
<table ng-controller="ctrl">
<tr>
<td>
<span opp-name="" input="opp.Name">
{{opp.Name}}
</span>
</td>
</tr>
</table>
</div>
JavaScript
var ngApp = angular.module('app', []);
//This directive strips off everything before and after underscore in the OppName. For example: OIf input is 111111_Test_123445 then output should be Test
ngApp.directive('oppName', function () {
return {
restrict: 'A',
scope: {
input: '=',
},
link: function (scope, element, attrs) {
console.log('Input: ', scope.input);
var input = scope.input;
if (!input) {
return;
}
// 111111_Test_123445
if (input.indexOf('_')) {
scope.input = input.split('_')[1];
}
}
};
});
ngApp.controller('ctrl', function($scope) {
$scope.opp = {
Id: 1,
Name: '111111_Test_123445'
};
});