how to call parent function controller from directive react component angularjs + reactjs?

user474901

I have angular application and we start using react as render data.we have one problem is how can we call $scope.showUserDetails from directive react component .I tried using this.props.scope.$parent.showUserDetails(); I have Uncaught TypeError: Cannot read property '$parent' of undefined

react component

 /** @jsx React.DOM */
var MYCOMPONENT = React.createClass({
    displayName: 'MYCOMPONENT',
    handleClick: function (e) {
        console.log('You clicked');
        this.props.scope.$parent.showUserDetails();
    },
    render: function (){     
        var listUser = this.props.data.map(function(item){

            return(
                React.DOM.div(
                    {
                        className: 'panel panel-default staff-reception ' + item.statusType.toLocaleLowerCase() + 'Office',
                        'ng-click': 'showUserDetails(' + item + ')',
                        onClick: this.handleClick
                    },
                    React.DOM.div(
                        {
                             className: 'panel-body'
                        },
                        React.DOM.span(null, item.firstName + ' ' + item.lastName + ' ' + item.directDial + ' Ext:' + item.voiceMailExt)
             )
             )
             );
        },this);

        return (React.DOM.div({className:'col-xs-12 col-md-6 col-lg-4'}, listUser));
    }
});

controller

(function () {

    'use strict';
    var app = angular.module('app');

    var ReceptionReactController = function ($scope, ReceptionReactService, $modal) {


        $scope.showUserDetails = function (user, index) {
            var modalInstance = $modal.open({
                templateUrl: 'UserDetails.html',
                controller: UserDetailsController,
                size: 'lg',
                resolve: {
                    user: function () {
                        return user;
                    }
                }
            });
            modalInstance.result.then(function (userUpdatedStatus) {
                updateUserStatus(userUpdatedStatus);

            }, function () {

            });
        };




    };

    app.controller('ReceptionReactController', ['$scope', 'ReceptionReactService', '$modal', '$window', ReceptionReactController]).directive('fastNg', function () {
        return {
            restrict: 'E',
            scope: {
                data: '='
            },
            link: function (scope, el, attrs){
                scope.$watch('data', function(newValue, oldValue){
                    React.render(React.createElement(
                          MYCOMPONENT, {
                              data: newValue
                          }),
                          el[0]
                        );
                });
            }
        }
    });

}());

view

 <fast-ng data="ListTitleUsers.users"></fast-ng>
Austin Greco

It seems like you should pass the function you want through the directive's attributes and into the react component's props. Something like this might work:

<fast-ng data="ListTitleUsers.users" show="showUserDetails"></fast-ng>

-

app.controller('ReceptionReactController', ['$scope', 'ReceptionReactService', '$modal', '$window', ReceptionReactController]).directive('fastNg', function () {
    return {
        restrict: 'E',
        scope: {
            data: '=',
            show: '='
        },
        link: function (scope, el, attrs){
            scope.$watch('data', function(newValue, oldValue){
                React.render(React.createElement(
                      MYCOMPONENT, {
                          data: newValue,
                          show: scope.show
                      }),
                      el[0]
                    );
            });
        }
    }
});

-

handleClick: function (e) {
    console.log('You clicked');
    this.props.show();
},

-

onClick: this.handleClick.bind(this, item)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

AngularJS How to call directive function from controller

From Dev

How to pass a value from an AngularJS directive to a function in parent controller

From Dev

how to call one directive controller function from another one directive using angularjs

From Dev

angularjs directive will not call controller function

From Dev

Angularjs directive call controller function

From Dev

Angularjs directive call controller function

From Dev

How to call a directive function from controller?

From Dev

AngularJS calling from Parent to Child Directive controller function

From Dev

Angularjs pass function from Controller to Directive (or call controller function from directive) - with parameters

From Java

Call a controller function from a directive without isolated scope in AngularJS

From Dev

Using AngularJs ControllerAs approach, How can I call a function in a parent controller from the child controller?

From Dev

How to pass data from controller to directive from ajax call AngularJS

From Dev

Access controller component function from a Directive component

From Dev

Access controller component function from a Directive component

From Dev

Unable to call parent controller method from directive

From Dev

How to call a function from another controller in angularjs?

From Dev

how to call controller function from template in angularjs

From Dev

How to call a function from a directive from an outside controller?

From Dev

Send Object From Directive to Parent Controller in AngularJS

From Dev

How to call angular controller scope function from directive with parameters?

From Dev

How to call angular controller scope function from directive with parameters?

From Dev

AngularJS Trigger directive from controller call

From Dev

How to pass a function handler from controller into directive isolated scope in AngularJs?

From Dev

How to pass a function handler from controller into directive isolated scope in AngularJs?

From Dev

EmberJS: How to call a component function from a controller and calculate the component data

From Dev

EmberJS: How to call a component function from a controller and calculate the component data

From Dev

pass function from parent controller to directive with parameter

From Dev

AngularJS Controller - Directive -> invokation of Controller function from directive

From Dev

how to call a function from another component in react

Related Related

  1. 1

    AngularJS How to call directive function from controller

  2. 2

    How to pass a value from an AngularJS directive to a function in parent controller

  3. 3

    how to call one directive controller function from another one directive using angularjs

  4. 4

    angularjs directive will not call controller function

  5. 5

    Angularjs directive call controller function

  6. 6

    Angularjs directive call controller function

  7. 7

    How to call a directive function from controller?

  8. 8

    AngularJS calling from Parent to Child Directive controller function

  9. 9

    Angularjs pass function from Controller to Directive (or call controller function from directive) - with parameters

  10. 10

    Call a controller function from a directive without isolated scope in AngularJS

  11. 11

    Using AngularJs ControllerAs approach, How can I call a function in a parent controller from the child controller?

  12. 12

    How to pass data from controller to directive from ajax call AngularJS

  13. 13

    Access controller component function from a Directive component

  14. 14

    Access controller component function from a Directive component

  15. 15

    Unable to call parent controller method from directive

  16. 16

    How to call a function from another controller in angularjs?

  17. 17

    how to call controller function from template in angularjs

  18. 18

    How to call a function from a directive from an outside controller?

  19. 19

    Send Object From Directive to Parent Controller in AngularJS

  20. 20

    How to call angular controller scope function from directive with parameters?

  21. 21

    How to call angular controller scope function from directive with parameters?

  22. 22

    AngularJS Trigger directive from controller call

  23. 23

    How to pass a function handler from controller into directive isolated scope in AngularJs?

  24. 24

    How to pass a function handler from controller into directive isolated scope in AngularJs?

  25. 25

    EmberJS: How to call a component function from a controller and calculate the component data

  26. 26

    EmberJS: How to call a component function from a controller and calculate the component data

  27. 27

    pass function from parent controller to directive with parameter

  28. 28

    AngularJS Controller - Directive -> invokation of Controller function from directive

  29. 29

    how to call a function from another component in react

HotTag

Archive