0

I am making a web app:front-end in Angular and backend in Rails. I am using LinkedIn's member profile plugin which shows person's profile based on URL being passed. Here is the code for this plugin.

<script src="//platform.linkedin.com/in.js" type="text/javascript"></script>
<script type="IN/MemberProfile" data-id="(Your LinkedIn URL)" data-format="inline" data-related="false"></script>

I want to make data-id part dynamic. Basically, I will let my users to write their linkedin address in text box and save it to Angular's variable. When the value changes, I want that value gets assigned to data-id. But I'm not sure whether data-id can access a variable in Angular.

1 Answer 1

1

Quite simple. Create your app along with a global controller that will be initialised on your html tag like so:

<html ng-app="app" ng-controller="myctrl">
  <head>
     <script type="IN/MemberProfile" data-id="{{myId}}" data-format="inline" data-related="false"></script>
  </head>
</html>

And have this as your controller and app initialisation, or something similar:

var app = angular.module('app', []);
app.controller('myctrl', ['$scope', function($scope){
  $scope.myId = 123;
}]);

To break it down, $scope.myId will be assigned the LinkedIn ID, and it is output on the page inside the head tag (I'm guessing that's where you want it) within the data-id attribute on the script tag.

WORKING EXAMPLE

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

7 Comments

Thanks. Can you also put ng-change in Script tag? Once user hits "save linkedin url" link, i want to input the value into the Script tag and populate the plugin.
@Jokingpsh - Are you after something like this? In that example, a user can input their ID into an input and click the update button. It is then saved and changed on the script tag.
That is what I was basically doing but the plugin was not being called correctly. I think it may be linkedin's plugin issue :/
Yes, probably is. The way around it may be to only create the tag once the user has entered a value and clicked save, like so: example. That example will only create the tag on the page once the user has clicked the save button. This way will not work if the user wants to change the ID again; that will require extra code.
I think it is linkedin's own problem. It successfully does the trick but it doesn't work as I want :/
|

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.