Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scope is not defined #41

Closed
simonghales opened this issue Jun 6, 2016 · 5 comments
Closed

scope is not defined #41

simonghales opened this issue Jun 6, 2016 · 5 comments

Comments

@simonghales
Copy link

simonghales commented Jun 6, 2016

at line 96 of the compiled file angular-off-click.js I'm getting a scope is not defined console error.

return $parse(attrs.offClickIf)(scope);

from

if (attrs.offClickIf) {
                removeWatcher = $rootScope.$watch(function () {
                    return $parse(attrs.offClickIf)(scope);
                }, function (newVal) {
                    newVal && on() || !newVal && off();
                });
            } else on();

Within the src offClick.js file that line is also 96

removeWatcher = $rootScope.$watch(() => $parse(attrs.offClickIf)(scope), (newVal) => {

from

if (attrs.offClickIf) {
                removeWatcher = $rootScope.$watch(() => $parse(attrs.offClickIf)(scope), (newVal) => {
                    newVal && on() || !newVal && off()
                });
            } else on();

My HTML

<sidebar ng-class="{
                'state--open': mainVM.states.sidebar.open
               }"
               off-click="mainVM.closeSidebar()"
               off-click-if="mainVM.states.sidebar.open"></sidebar>

Looks like the recent commit that rewrote the js as ES6 might have a few bugs. For now I've reverted to an older version and everything is working fine.

@Ricardo-Marques
Copy link
Collaborator

Ricardo-Marques commented Jun 6, 2016

Hello @simonghales !
My apologies for this, I had this code working on a project locally and whilst transferring it here I made a few mistakes - the latest version (1.0.1) should address all the underlying issues caused by the refactor.

Please confirm so I can close this issue.

@simonghales
Copy link
Author

Hey @Ricardo-Marques

Seems there's still at least one issue remaining, although those changes did fix up the previous errors.

angular.js:12798 Error: [$parse:lexerr] Lexer Error: Unexpected next character  at columns 0-0 [#] in expression [#sidebar].
http://errors.angularjs.org/1.4.11/$parse/lexerr?p0=Unexpected%20nextharacter%20&p1=s%200-0%20%5B%23%5D&p2=%sidebar
    at http://localhost:3002/bower_components/angular/angular.js:68:12
    at Lexer.throwError (http://localhost:3002/bower_components/angular/angular.js:13021:11)
    at Lexer.lex (http://localhost:3002/bower_components/angular/angular.js:12980:16)
    at Object.ast (http://localhost:3002/bower_components/angular/angular.js:13143:30)
    at Object.compile (http://localhost:3002/bower_components/angular/angular.js:13597:31)
    at Parser.parse (http://localhost:3002/bower_components/angular/angular.js:14476:29)
    at $parse (http://localhost:3002/bower_components/angular/angular.js:14584:39)
    at http://localhost:3002/app/vendors/angular-off-click.js:121:27
    at invokeLinkFn (http://localhost:3002/bower_components/angular/angular.js:9089:9)
    at nodeLinkFn (http://localhost:3002/bower_components/angular/angular.js:8576:11)

So line 121 of the compiled angular-off-click.js file.

filters = $parse(attrs.offClickFilter)(scope).split(',').map(function (x) {

From offClickFilter.js

filters = $parse(attrs.offClickFilter)(scope).split(',').map(x => x.trim());

So it would seem the issue is related to the parsing of the IDs I provided to the filter.

I appreciate the quick response.

@Ricardo-Marques
Copy link
Collaborator

Ricardo-Marques commented Jun 7, 2016

@simonghales That's a mistake in the docs, again, by me.

off-click-filter gets parsed as Javascript, so, you have to wrap it as a string,
off-click-filter="'#sidebar'"

Going to edit that now.

@simonghales
Copy link
Author

Awesome, everything seems to be working now.

@Ricardo-Marques
Copy link
Collaborator

Excellent.

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

No branches or pull requests

2 participants