Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Component controller #13742

Closed
wants to merge 5 commits into from
Closed

Conversation

drpicox
Copy link
Contributor

@drpicox drpicox commented Jan 11, 2016

See PR: #13732
See Issue: #13683

Now $componentController looks for the directive that represents a component which is the one that satisfies:

  • it has at least restrict:'E' (other are valid if they contain 'E')
  • it has controller
  • it has controllerAs.

Tests are added to evaluate under multiple scenarios commented in the original thread.

PS: I created the new PR to solve conflicts with minimum "dirtiness".

// look for those directives that are components
var candidateDirectives = directives.filter(function(directiveInfo) {
// components have controller, controllerAs and restrict:'E' compatible
return directiveInfo.controller && directiveInfo.controllerAs && directiveInfo.restrict.indexOf('E') >= 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can just check === 'E' rather than indexOf('E')

@drpicox
Copy link
Contributor Author

drpicox commented Jan 12, 2016

I tried to add minErr,

angular.mock.$ComponentControllerProvider = ['$compileProvider', function($compileProvider) {
  var minErr = angular.$$minErr('$componentController');
  return {
    $get: ['$controller','$injector', function($controller,$injector) {
      return function $componentController(componentName, locals, bindings, ident) {
        // get all directives associated to the component name
        var directives = $injector.get(componentName + 'Directive');
        // look for those directives that are components
        var candidateDirectives = directives.filter(function(directiveInfo) {
          // components have controller, controllerAs and restrict:'E'
          return directiveInfo.controller && directiveInfo.controllerAs && directiveInfo.restrict === 'E';
        });
        // check if valid directives found
        if (candidateDirectives.length === 0) {
          throw minErr('nocomp','No \'{0}\' component found', componentName);
        }
        if (candidateDirectives.length > 1) {
          throw minErr('multicomp','Found {0} directive candidates for component \'{1}\'', candidateDirectives.length, componentName);
        }
        // get the info of the component
        var directiveInfo = candidateDirectives[0];
        return $controller(directiveInfo.controller, locals, bindings, ident || directiveInfo.controllerAs);
      };
    }]
  };
}];

but I'm getting this error from grunt test:

error:   TypeError: Cannot read property 'nocomp' of undefined
    at /Users/drodenas/Projects/drpicox/angular.js/docs/config/processors/error-docs.js:43:76
    at Array.forEach (native)
    at Object.$process (/Users/drodenas/Projects/drpicox/angular.js/docs/config/processors/error-docs.js:18:12)
    at /Users/drodenas/Projects/drpicox/angular.js/node_modules/dgeni/lib/Dgeni.js:202:28
    at _fulfilled (/Users/drodenas/Projects/drpicox/angular.js/node_modules/dgeni/node_modules/q/q.js:798:54)
    at self.promiseDispatch.done (/Users/drodenas/Projects/drpicox/angular.js/node_modules/dgeni/node_modules/q/q.js:827:30)
    at Promise.promise.promiseDispatch (/Users/drodenas/Projects/drpicox/angular.js/node_modules/dgeni/node_modules/q/q.js:760:13)
    at /Users/drodenas/Projects/drpicox/angular.js/node_modules/dgeni/node_modules/q/q.js:821:14
    at flush (/Users/drodenas/Projects/drpicox/angular.js/node_modules/dgeni/node_modules/q/q.js:108:17)
    at doNTCallback0 (node.js:419:9)

I have added the directory $componentController with files multicomp.ngdoc and nocomp.ngdoc to docs/content/error.

I ran out of time. ¿Any clue how to solve it?

Thanks!

PS: I did not pushed back the changes because are breaking check passes, but I can push them if you ask for it.

@gkalpak
Copy link
Member

gkalpak commented Jan 12, 2016

Not sure what might be causing the issue. IF you push the changes (with minErr), even if broken, it will be easier to identify the problem (and the solution 😃).

… (fail due to TypeError: Cannot read property 'nocomp' of undefined)

    at /Users/drodenas/Projects/drpicox/angular.js/docs/config/processors/error-docs.js:43:76)
@drpicox
Copy link
Contributor Author

drpicox commented Jan 12, 2016

Thanks!
Done, breaking commit away.

@petebacondarwin petebacondarwin self-assigned this Jan 12, 2016
@petebacondarwin petebacondarwin added this to the 1.5.0-rc.1 milestone Jan 12, 2016
@petebacondarwin
Copy link
Contributor

I'll take a look now

@petebacondarwin
Copy link
Contributor

The problem is that we were not minifying the angular-mocks.js file (unsurprisingly) and so the errors.json file did not contain the minErr error information, which is needed.

So looking at this again, I realise now that we don't use minErr in the rest of ngMock and so I was wrong to suggest that we use it here. Sorry.

@petebacondarwin
Copy link
Contributor

I will review and merge the rest of the PR without this last commit

@drpicox
Copy link
Contributor Author

drpicox commented Jan 12, 2016

No problem at all, I used throw new Error in the first approach because is what I found inside the angular-mock.js code.
Anyway it was nice to explore how minErr is working.

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants