Last active
March 16, 2016 11:19
-
-
Save LarsVonQualen/4384c4fadf543d0d4848 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export abstract class BaseModel { | |
public static mapFromObject<TModel>(obj: any, modelFactory?: () => TModel): TModel { | |
if (!angular.isObject(obj)) return null; | |
var result = angular.isFunction(modelFactory) ? modelFactory() : new (this as any)(); | |
angular.forEach(obj, (val, key) => result[key] = val); | |
return result; | |
} | |
public static mapFromArray<TModel>(arr: Array<any>, modelFactory?: () => TModel): Array<TModel> { | |
if (!angular.isArray(arr)) return null; | |
return arr.map(val => BaseModel.mapFromObject<TModel>(val, modelFactory)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment