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

Remove bind for stPipe #200

Closed
srph opened this issue Oct 27, 2014 · 8 comments
Closed

Remove bind for stPipe #200

srph opened this issue Oct 27, 2014 · 8 comments

Comments

@srph
Copy link

srph commented Oct 27, 2014

The stPipe directive is causing me issues. In my case, I am using a Base Controller, using $controller to be prototypically inheritted. Here's a plunkr for demonstration purposes.

With this being binded to the function, this causes me issues: I am unable to access my own controller's this. Perhaps a version of stPipe without the bind (st-pipe-no-bind, ...)?

@lorenzofox3
Copy link
Owner

Or just use a variable to identify your controller in a closure of the pipe function.

var self=this;

function customPipe(tablestate){
     // this refer to the table controller
    // self refer to your controller
}

But you are right it is anyway a bad practice to bind a function to a "hidden this" I should pass the table controller instance as parameter of the function.

@srph
Copy link
Author

srph commented Oct 27, 2014

I appreciate the quick reply.

I could as you instructed. But, like I mentioned: I am using this. I could use a variable that refers to this, but this would cause it to target my Base Controller (see this question). If ever I made a workaround, this will rise an issue on inconsistency.

Will there be any updates soon? Thanks.

@srph
Copy link
Author

srph commented Oct 28, 2014

It still uses stTable's this instead of mine. While it's possible that I'm doing this poorly, I'm just still kind of confused to why this still happens. I apologize for the bother. I was able to make a workaround, but it feels hackish. Is it me, or I could only make it work with this hack (it feels hackish):

// js
var vm = this,
    collection = [];

vm.collection = collection;
vm.getPageData = getPageData;

function getPageData(query) {
      ...
        .then(fn..)
        .catch(fn..);
}

$scope.call = function(tableState) {
  vm.callServer(tableState);
}
<!-- template (controllerAs syntax) -->
<table st-table="scholarships.collection" class="table table-hover table-clickable" st-pipe="call">

@lorenzofox3
Copy link
Owner

not sure to understand your problem now ?
in this example example you have a custom pipe function and controller as syntax

@srph
Copy link
Author

srph commented Oct 29, 2014

See this plunkr. In this case, this refers to stPipe's instead of the controller's

@lorenzofox3
Copy link
Owner

This actually refers to the scope created by the spPipe directive.

If you really want to use this you can force the context like here but I don't understand why you can't use a closure

@srph
Copy link
Author

srph commented Oct 29, 2014

I was using the "bind" in a wrong way. I tried to pass it to the stPipe binded in the template, like <.. st-pipe="angular.bind(main, main.callServer)" which was producing different results from the expected. I also tried different ways, but not exactly this. I don't know why I didn't came across this thought. This may be due to recklessness and inexperience.

Alright! Thanks again, sir.

@frankmunoz
Copy link

frankmunoz commented May 6, 2016

Hi @lorenzofox3 and @srph, what I need is almost that, I'm reusing the same table with different data, and I need set in the function of st-pipe attribute a param to let the function knows how work it, something like this

// js
$scope.myHandler = function(tableState, myParameter) {
//manipulate here myParameter
}

//html
div class="table-responsive" st-table="vm.myCollection" st-pipe="vm.myHandler(myParameter)"

I hope this be clear because my english is not pretty good!!
Some one knows how can I solve it??

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

3 participants