Search code examples
typescriptsharepoint-onlineinnerhtmlspfxmicrosoft-graph-api

MSGraph - Is it possible to slice an attribute called from an API?


I am using MGT (Microsoft Graph Toolkit) and was wondering if it was possible to slice an attribute. Here is my code:

                <mgt-person person-query="me">
                  <template>
                   <div>
                    {{person.displayName}}
                   </div>
                  </template>
                <template data-type="loading">
                   Loading
                </template>
                 </mgt-person>

person.DisplayName Returns : "Smith, John"

How do just get the first name from this? I want to slice out the last name and the ",".

I know {{person.givenName}} will give you the first name but for various reasons, some users have a different name in their display name they prefer to be called by.

Please help.


Solution

  • You could use js to achieve this:

    person.displayName.split(",")[0]