Reputation: 93
I would like to embed my PowerBi Dashboard into an HTML file using JavaScript from the sample code from this GitHub. The error that I am getting is:
Unable to get property 'models' of undefined or null reference
Am I missing a .js
file that needs to be added to the head section?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.7.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.10/jquery-ui.js"></script>`
<script>
$(document).ready(function () {
// Get models. models contains enums that can be used.
var models = window['powerbi-client'].models;
var embedConfiguration = {
type: 'dashboard',
id: 'dashboardid',
embedUrl: 'https://app.powerbi.com/reportEmbed',
tokenType: models.TokenType.Aad,
accessToken: 'TokenKey'
};
var $dashboardContainer = $('#embedContainer');
var dashboard = powerbi.embed($dashboardContainer.get(0), embedConfiguration);
});
</script>
</head >
<body>
<div id="dashboardContainer"></div>
</body >
</html >
Upvotes: 1
Views: 1157
Reputation: 967
You can try with,
<script src="https://raw.githubusercontent.com/Microsoft/PowerBI-JavaScript/master/dist/powerbi.js"></script>
Upvotes: 0
Reputation: 1722
You need to include ECMAScript 6 (ES6):
<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.35.3/es6-shim.js"></script>
You'll also need to load the actual PowerBi library, along with any necessary JS files, since it doesn't appear that you are already doing so, at least in the code you provided.
You're also assigning the variable, $dashboardContainer
, the value of $('#embedContainer')
which isn't an element in the HTML you provided. You used the ID of #dashboardContainer
in your HTML.
Upvotes: 1