0

I have some project on Angular CLI. So I need to put some scripts to a component but it seems they arent there

my code in the component:

    <script src="//vk.com/js/api/openapi.js" type="text/javascript"></script>
<div id="login_button" ></div>
<script language="javascript ">
    VK.init({
      apiId: 6241489
    });
    /*function authInfo(response) {
      if (response.session) {
        alert('user: '+response.session.mid);
        } else {
        alert('not auth');
        }
    }
    VK.Auth.getLoginStatus(authInfo);*/
    VK.UI.button('login_button');
    </script>

Who know how to fix it?

2 Answers 2

1

First, load the third-party script by adding it to the apps[0].scripts property in .angular-cli.json as described in Angular CLI doc.

Then, make the global VK object accessible in your component by definining declare var VK: any; and call VK.init() from your component's ngOnInit(). I assume that will be the AppComponent.

Sign up to request clarification or add additional context in comments.

1 Comment

@tatamingi Please mark the answer as accepted by clicking the gray check mark under the counter at the left
1

I don't believe you're supposed to create script tags in your component.html files.

If you want to fire the supposed function, try this.

.ts file:

authInfo() {
    // Where does response params come from?
    if (response.session) {
        alert('user: '+response.session.mid);
    } else {
        alert('not auth');
    }
}

.html template:

<button (click)="authInfo()"></button>

Please reply to this answer with more detail so I can assist you further :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.