question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NG1 ES6 components usage

See original GitHub issue

Hi Hackers!

I was wondering, is there an example using a dynamic label from $scope => using ES6 Classes?

For example:

const testConfig = function($stateProvider) {
  "ngInject";

  $stateProvider
    .state('testShow', {
      url: '/{id:[0-9]+}',
      component: 'testShow',
      ncyBreadcrumb: {
        parent: 'test',
        label: 'Edit {{ $ctrl.name }}'
      }
    });
};

export default testConfig;

I am not able to use name, $ctrl.name nor $scope in the config route for this PoC.

import template from './index.html';
import controller from './controller';
import './styles.styl';

let testShowComponent = {
  restrict: 'E',
  bindings: {},
  template,
  controller,
  controllerAs: '$ctrl'
};

export default testShowComponent;
import {Controller} from 'es6-angular-util';

class TestShowController extends Controller {
  constructor($scope) {
    "ngInject";

    // required by es6-angular-util
    super($scope);

    this.name = 'TEST THIS';

    $scope.name = 'TEST $SCOPE';
  }
}

Any help is welcome, thanks!

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:4
  • Comments:10

github_iconTop GitHub Comments

9reactions
kristofdegravecommented, Dec 12, 2016

A possible solution is to use reslove in your route. If you do this you can access the $resolve of the ui-router

$stateProvider
    .state('testShow', {
      url: '/{id:[0-9]+}',
      component: 'testShow',
      resolve: resolve: {
           id: ["$stateParams", function($stateParams) {
              return $stateParams.id;
          }]
      },
      ncyBreadcrumb: {
        parent: 'test',
        label: 'Edit {{ $resolve.id }}'
      }
    });

An other option is to use an inner property of angular called $$childHead (which retrieves a child scope)

$stateProvider
    .state('testShow', {
      url: '/{id:[0-9]+}',
      component: 'testShow',
      ncyBreadcrumb: {
        parent: 'test',
        label: 'Edit {{ $$childHead.$ctrl.name }}'
      }
    });
1reaction
blowsiecommented, Dec 12, 2017

@biltongza yep, thanks I already had this in my config too, usefeull for @tonestrike to know.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Preparing your Angular 1 codebase to upgrade to React or ...
First, we can remove the wrapping IIFE since Webpack will package each file in its own closure. We can also remove 'use strict'...
Read more >
Guide: Route to Component - UI-Router
An AngularJS 1.5 component is a reusable piece of a web page, which encapsulates both structure (markup) and behavior. A component is self- ......
Read more >
Writing Reusable Components in ES6 - Smashing Magazine
Used extensively in webpack, loaders can do things like transpile ES6 to ES5, Less to CSS, load JSON files, render templates and much...
Read more >
Upgrading from AngularJS to Angular
In your Angular application, you need a component as a placeholder for your AngularJS content. This component uses the service you create to...
Read more >
How To Use Es6 Syntax In React Functional Component
In this video I have shown how to use Es6 syntax for creating React Functional Component. Es6 syntax in React. React Es6 syntax....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found