Oh, I see it is yet another feature blocked by the custom visual sanboxing. At the moment, there are two known official(And not very satisfying) ways to overcome this issue:
1. Using the temporary "unsandboxing" flag(adding "?sandboxVisualsEnabled=false" to pbi-service url).
2. Uploading the visual to the custom visuals gallery(because all visuals in the gallery have their code reviewed by Microsoft).
As noted by Bashir from the PowerBI Platform Team in the following post: