Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // To add in a HelperService :)
- static recursiveValue(value:string, obj:any, translate:boolean = false) {
- let splitted;
- if(value.indexOf('.')) {
- splitted = value.split('.');
- } else {
- splitted = [value];
- }
- if(angular.isDefined(obj[splitted[0]])) {
- if(angular.isArray(obj[splitted[0]]) || angular.isObject(obj[splitted[0]])) {
- let splittedFirst = angular.copy(splitted[0]);
- return this.recursiveValue(this.splittedToStr(splitted, 0), obj[splittedFirst]);
- } else {
- return obj[splitted[0]];
- }
- }
- }
- static splittedToStr(splitted, i = 0) {
- if(splitted.length === 1) {
- return splitted[0];
- }
- splitted = splitted.slice(1, i);
- return splitted.join('.');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement