Ad
Getting Typescript Error In Angular , Not Able To Bind This Properly
const stateObj = {
indicators: stateIndicators,
filters: stateFilters,
benchmarks: stateBenchmarks,
request: stateRequest,
ready: stateReady,
visualization: stateVisualization,
dimensions: stateDimensions,
datasets: stateDatasets
};
extend({
getDefaultIndicators: function () {
return stateObj.indicators.enabledIndicators
.map((indicator) => find(stateObj.indicators.indicators, { name: indicator }));
},
getEnabledIndicators: function () {
return this.request.indicators
.map((i) => find(stateObj.indicators.indicators, { name: i }));
},
getEnabledBenchmarks: function () {
return filter(stateObj.benchmarks, 'selected');
},
save: function () {
if (tile) { return; }
let serializedState = this.serialize();
this.userStorage.saveExploreState(entity, serializedState);
},
serialize: function () {
return {
request: this.request,
benchmarks: map(this.getEnabledBenchmarks(), 'name'),
visualization: this.visualization,
dimensions: this.dimensions,
datasetId: datasetId
};
}
}, stateObj);
Property 'request' does not exist on type '{ getDefaultIndicators: () => (Indicator | undefined)[]; getEnabledIndicators: () => any; getEnabledBenchmarks: () => { selected: boolean; name: string; }[]; save: () => void; serialize: () => any; }
Extend is lodash function I am getting type error for 'this.dimensions', 'this.visualization' as 'this' is not binding with stateObj and also 'this.userStorage' is class property , How to fix this issue.
Ad
Answer
Use arrow function to bind this context.
Try this:
extend({
getDefaultIndicators: () => {
return stateObj.indicators.enabledIndicators
.map((indicator) => find(stateObj.indicators.indicators, { name: indicator }));
},
getEnabledIndicators: () => {
return this.request.indicators
.map((i) => find(stateObj.indicators.indicators, { name: i }));
},
getEnabledBenchmarks: ()=> {
return filter(stateObj.benchmarks, 'selected');
},
save:() => {
if (tile) { return; }
let serializedState = this.serialize();
this.userStorage.saveExploreState(entity, serializedState);
},
serialize: ()=> {
return {
request: this.request,
benchmarks: map(this.getEnabledBenchmarks(), 'name'),
visualization: this.visualization,
dimensions: this.dimensions,
datasetId: datasetId
};
}
}, stateObj);
Ad
source: stackoverflow.com
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
Ad