Code Monkey home page Code Monkey logo

Comments (7)

bcherny avatar bcherny commented on June 7, 2024 1

@rattrayalex Feel free to post your code/question in this thread if I can help!

from react2angular.

bcherny avatar bcherny commented on June 7, 2024

To clarify- You are trying to rewrite an Angular component as a React component, but are not sure what to do with a listener on the component's scope? Let me know if that's right.

In either case, a code sample would be helpful, as there are a few approaches you could take depending on the situation.

from react2angular.

matiasfha avatar matiasfha commented on June 7, 2024

Right. I'm trying to "translate" an angular directive to a React component.
In this case the directive have a listener ($scope.$on('custom:event') ).

code example

var directive = function($rootScope, $window) {
return {
   template,
   restrict: 'E',
   scope: { 
      interactive: '@'
   },
  controller: function($scope){
    //do some stuff
  },
  link: function(scope, element, attrs, controller){
    scope.$on('destroy', cleanup) //clearly this can be achieved with componentWillUnMount 
    
    // This event comes from another controller that use $rootScope.$broadcast
   // Can i access to the $scope from the react component? Can $scope be passed as prop?
    scope.$on('edit-pane:toggled', function() {
       setTimeout(performTheTask, 750)
    })
  }
}```

from react2angular.

bcherny avatar bcherny commented on June 7, 2024

I see. I would say you have 2 good options:

  1. If the event is local, pass scope in as a prop on your component
  2. If the event is on $rootScope, use ngimport to import $rootScope in your React component

from react2angular.

bcherny avatar bcherny commented on June 7, 2024

@msdark Feel free to reopen if the above suggestions don't work for you.

from react2angular.

rattrayalex avatar rattrayalex commented on June 7, 2024

@msdark curious what you ended up going with

from react2angular.

rattrayalex avatar rattrayalex commented on June 7, 2024

Thanks @bcherny ! No immediate use-case, but I appreciate the offer!

from react2angular.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.