Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
MikeAinOz
Helper III
Helper III

Using AngularJS in Custom Visual

I'm trying out AngularJS in a custom visual. I've got the  AngularJS modules library in and building and not I'm trying to build a test app.

 

I've created some html in the  constructor:

 

                const ang_app: HTMLElement = document.createElement("div");
                ang_app.setAttribute('ng-app',"myapp");
                ang_app.setAttribute('ng-controller',"tableController");
                const ang_tr: HTMLElement = document.createElement("tr");
                ang_tr.setAttribute('ng-repeat',"row in dataSet");
                ang_app.appendChild(ang_tr);
                const ang_td: HTMLElement = document.createElement("td");
                ang_td.appendChild(document.createTextNode("{{row[0]}}"));
                ang_app.appendChild(ang_td);
                this.target.appendChild(ang_app);

and checked the resulting HTML, which looks OK:

<div ng-app="myapp" ng-controller="tableController">
<tr ng-repeat="row in dataSet"></tr><td>{{row[0]}}</td></div>

 

I'm using angular in the Update method like this:

 

 

           var app = ng.module("myapp",[]);
            app.controller("tableController", ['$scope', function ($scope) {
                $scope.dataSet = options.dataViews[0];
            }],
            );

 

So it looks fairly close, but I'm obviously missing something. Does any one have a suggestion or is there sample code I can look at?

 

I'm getting this error:

SCRIPT5022: SCRIPT5022: [$injector:modulerr] Failed to instantiate module myapp due to: Error: [$injector:nomod] Module 'myapp' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument. https://errors.angularjs.org/1.7.4/$injector/modulerr?p0=myapp&p1=Error%3A%20%5B%24injector%3Anomod%...

1 ACCEPTED SOLUTION
v-viig
Community Champion
Community Champion

Your code above is almost correct. You can also learn how to pass props in React Doc.

 

ReactDOM.render(React.createElement(App, {options}), this.element);

 

 

You should also add options as props into App.

 

Ignat Vilesov,

Software Engineer

 

Microsoft Power BI Custom Visuals

pbicvsupport@microsoft.com

View solution in original post

9 REPLIES 9
v-viig
Community Champion
Community Champion

Have not tried Angular but we have small sample for React.

 

Ignat Vilesov,

Software Engineer

 

Microsoft Power BI Custom Visuals

pbicvsupport@microsoft.com

Hey Ignat thanks for that, it's an interesting alternative, I'll let you know how it works out (you might get another question for react 🙂 )

v-viig
Community Champion
Community Champion

Happy to help.

 

Current samplkes does not look good since it does not use modern ES2015 features such as modules but we're working on webpack based pbiviz to bring new features to developers.

 

Ignat Vilesov,

Software Engineer

 

Microsoft Power BI Custom Visuals

pbicvsupport@microsoft.com

Ignat, I can't figure out how to get the dataView into the React Component.

 

I'm doing this is in Update: 

ReactDOM.render(React.createElement(App, options), this.element);
 
but what do I do in the App.tsx? I've managed to pass a test string, but how to pass the VisualUpdateOptions object?
 
Having had a play with React, it looks like a good way to create Custom Visuals
v-viig
Community Champion
Community Champion

Your code above is almost correct. You can also learn how to pass props in React Doc.

 

ReactDOM.render(React.createElement(App, {options}), this.element);

 

 

You should also add options as props into App.

 

Ignat Vilesov,

Software Engineer

 

Microsoft Power BI Custom Visuals

pbicvsupport@microsoft.com

I'm having some trouble getting that working. I've run out of time to work on it, but I was thinking of getting a programmer to get the example working for me. Is it worth doing that or will there be something else coming along? 

v-viig
Community Champion
Community Champion

We have not plans to implement Angular/React sample for Power BI but it's on our backlog (no ETA).

 

Ignat Vilesov,

Software Engineer

 

Microsoft Power BI Custom Visuals

pbicvsupport@microsoft.com

I found using Chrome to debug I culd see inside the object more easily using console.log. The props were being passed just fine, it was a user problem 😞 

v-viig
Community Champion
Community Champion

Awesome.

 

Ignat Vilesov,

Software Engineer

 

Microsoft Power BI Custom Visuals

pbicvsupport@microsoft.com

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors