OfficeDev / Office-Addin-TaskPane-Angular

Template to get start started writing a TaskPane Office Add-in for the Angular framework using TypeScript
Other
14 stars 19 forks source link

Issue with the Angular Interpolation #114

Open fahad198 opened 3 years ago

fahad198 commented 3 years ago

Prerequisites

Please answer the following questions before submitting an issue. YOU MAY DELETE THE PREREQUISITES SECTION.

Expected behavior

I created an app for outlook addIn. The notation under interpolation ({{}} brackets ) must be replaced with the value. It doesn't seems to work.

Current behavior

Its just {{caseTypeInternal?.firstApplicant?.name}}

Steps to Reproduce

I don't have any reproduction steps. It seems to work in the local host but doesn't work when I deploy it to the server. It used to work fine previously until I updated the angular and node.

Context

Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.

Failure Logs

Please include any relevant log snippets, screenshots or code samples here. image

AlexanderFinkbeiner commented 3 years ago

Are the angular directives like *ngIf working? If not it could also be related to this issue: Angular directive from Angular CommonModule not loaded correctly after building the App

To which angular version did you updated?

fahad198 commented 3 years ago

the directives are working fine ... Even the control like input or telerik controls are getting set properly ... It's only the interpolation that is not working and I have tried to downgrade node and angular cli still same.

AlexanderFinkbeiner commented 3 years ago

As workaround you could do the same thing as I did: https://github.com/OfficeDev/generator-office/issues/600#issuecomment-776102512

mpk commented 3 years ago

For anyone having problems with this:

I debugged Angular (version 11.2) JIT compiler and found out it depends on String.prototype.startsWith function to detect "{{" and "}}" interpolation brackets.

However, Office.js loads a MicrosoftAjax.js file, which includes lots of polyfills which forcefully rewrites native browser functions (including String.prototype.startsWith). The problem is that their polyfill is broken and does not have support for "position" argument which Angular expects.

Until Microsoft fixes this, I see two workarounds: 1) use AOT 2) protect startsWith function from being rewritten using something like Object.defineProperty(String.prototype, 'startsWith', { writable: false }) (seems like a hack, I have not tested it anywhere except Chrome...)