+ Start a Discussion
Aakanksha SinghAakanksha Singh 

Passing values from vf page to lightning component through a shared controller

Hello everyone,
Is there any way to pass the value of an input text field in the vf page to lightning component, through a shared controller??

Thank You
Aakanksha Singh
_Zach Boyd_Zach Boyd
One option would be to dispatch a lightning event with the text field value from the Visualforce page to the lightning component. I have included a link to a blog post that shows how you can fire events from visualforce and handle within lightning.

Aakanksha SinghAakanksha Singh
Hello Zach,
Thanks fo answering, but I don't have to use app, in my case lightning component itself is a tab.
Thanks once again
_Zach Boyd_Zach Boyd
Could you explain a little more on how you have it setup? In my original response I thought you had a lightning page with a visualforce component on the page. It should help me give a recommended approach. 
Aakanksha SinghAakanksha Singh
Well, its like thats my setup, but i'm not using lightning application, its just the component. I'm sharing the code.
<pre><!--Lightning Component--><aura:component controller="recieveVal">
    <aura:attribute name="vfVal" type="String" default=""/>
    <aura:attribute name="ifmsrc" type="String" default=""/>
    <aura:handler name="init" value="{!this}" action="{!c.myAction}"/>
    <ui:button press="{!c.getValue}">Get Value</ui:button><br/><br/>
    <iframe id="myFrame" style="border: 1px solid" src="{!v.ifmsrc}" />

<pre>//component controller
    myAction : function(component, event, helper) {
        component.set("v.ifmsrc", 'https://wk-aakanksha-dev-ed.lightning.force.com/apex/recieveVal');
    getValue : function(component, event, helper) {
        var action = component.get("c.getVfVal");
            var state = action.getState();
         var d = new Date();
         var n = d.getTime();  
         component.set("v.ifmsrc", 'https://wk-aakanksha-dev-ed.lightning.force.com/apex/recieveVal?t='+ n+'&var='+val );

<pre>//Apex Controller
public with sharing class recieveVal {
    public static string VfPageVar{get; set;}
    public static void sendValue(){
        if(str != VfPageVar){
            str = VfPageVar;
    private static string str;
    public static string getVfVal(){
        return str;

<pre><!--Vf page-->
<apex:page controller="recieveVal" showHeader="false" standardStylesheets="false">
    <apex:form id="theform">
            <apex:inputText value="{!VfPageVar}">
                <apex:actionSupport event="onchange" action ="{!sendValue}"/>
            page variable:
            <apex:outputText value="{!VfPageVar}" id="VfPage"/>
i have a one question what is  showData.sendValue(); (line number14 on apex class) ?
Aakanksha SinghAakanksha Singh
I'm sorry.. its not showdata, its recieveVal the class name.