0

I am adding Social Logins to my web app. Now I do a get on our webapi to get the available logins and then use an ng-repeat to list the buttons.

I have the following service;

var _getExternalProviders = function () {

    var returnUrl = "#";
    var externalProviderUrl = ngAuthSettings.apiServiceBaseUri + "api/Account/ExternalLogins?returnurl=" + returnUrl
                                                                + "&generateState=true";

    return $http.get(externalProviderUrl).then(function (results) {
        return results;
    });
};

i then call this service from my controller;

   authService.getExternalProviders().then(function (results) {
           $scope.externalProviders = results.data;  
        },
    function (err) {
        $scope.message = err.error_description;
    });

and my view is as follows;

<div data-ng-controller="loginController">
    <div data-ng-repeat="provider in externalProviders">
        <button class="btn btn-large btn-{{provider.name.toLowerCase() == 'microsoft' ? 'windows' : provider.name.toLowerCase()}} btn-block" type="button" data-ng-click="authExternalProvider('{{provider.name}}')"><i class="fa fa-{{provider.name.toLowerCase() == 'microsoft' ? 'windows' : provider.name.toLowerCase()}}"></i> | Connect with {{provider.name}}</button>
    </div>
</div>

(which is added to the parent view using an ng-include)

    <div ng-include="'app/views/externalProviders.html'">
    </div>

Now this is working and the buttons are returning and rendering great, and when I inspect the html

data-ng-click="authExternalProvider('{{provider.name}}')"

is rendering as

data-ng-click="authExternalProvider('Google')"

for example, however when i click the element the function is being passed '{{provider.name}}' as a string instead.

The cothroller method for the ng-click is as follows;

$scope.authExternalProvider = function (provider) {

    console.log(provider);

    var redirectUri = location.protocol + '//' + location.host + '/authcomplete.html';

    var externalProviderUrl = ngAuthSettings.apiServiceBaseUri + "api/Account/ExternalLogin?provider=" + provider
                                                                + "&response_type=token&client_id=" + ngAuthSettings.clientId
                                                                + "&redirect_uri=" + redirectUri;
    window.$windowScope = $scope;

    var oauthWindow = window.open(externalProviderUrl, "Authenticate Account", "location=0,status=0,width=600,height=750");
};

Can anyone tell me what I am doing wrong please?

2
  • what data type u required to be passed as? , if its not a string . I think it should be string Commented Feb 1, 2016 at 11:04
  • Yes just a string to be passed. Then I'm just passing that string across to the api. Commented Feb 1, 2016 at 11:10

1 Answer 1

1
data-ng-click="authExternalProvider('{{provider.name}}')" 

gets interpreted as JavaScript so what you really want is

data-ng-click="authExternalProvider(provider.name)"
Sign up to request clarification or add additional context in comments.

1 Comment

thanks for that. I assumed that angular still parsed in the variables names so the {{ }} was required.

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.