Skip to content

fix: changes to ui-sref in curly braces does not update $state.href #1449

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

Closed
wants to merge 3 commits into from

Conversation

guilbep
Copy link

@guilbep guilbep commented Oct 13, 2014

for instance:
if we had something like: <a ui-sref="test && test.go($stateParams)">Yiahoh</a> and that the test.go() call changed from "parent.tip({test : "test2"})" to "parent.tip({test: 'test3'})" it didn't update the var params in the directive.

… didn't update $state.href

for instance:
 if we had something like:  <a ui-sref="test && test.go($stateParams)">Yiahoh</a>  and that the test.go() call changed from  "parent.tip({test : "test2"})" to "parent.tip({test: 'test3'})"  it didn't worked.
@guilbep
Copy link
Author

guilbep commented Oct 13, 2014

Also.. maybe it breaks something. gonna try to find the test suite. Also maybe it was on purpose.. not sure :) I'm doing some tricky things.

@guilbep guilbep changed the title fix: if ui-sref is in curly braces (string), changes occured it didn't update $state.href fix: changes to ui-sref in curly braces does not update $state.href Oct 13, 2014
@guilbep guilbep closed this Oct 13, 2014
@guilbep guilbep reopened this Oct 13, 2014
@guilbep
Copy link
Author

guilbep commented Oct 13, 2014

I tried writing some test.. but

    function buildCustomDom($rootScope, $compile){
        scope = $rootScope.$new();

        el = angular.element(
            '<a ui-sref="{{go()}}">Details</a>');

        scope.contact = { id: 5 };
        scope.go = function() {
            var s = "contacts.item.detail(";
            s += "{id: '" + scope.contact.id + "'})";
            return s;
          };
        el = $compile(el)(scope);
        scope.$digest();
    }
    describe('links2', function() {
      beforeEach(inject(buildCustomDom));

      it('should update the href when uiSref changes', function() {
        expect(el.attr('href')).toBe('#/contacts/5');
        scope.contact.id = 6;
        scope.$apply();
        expect(el.attr('href')).toBe('#/contacts/6');
      });
    });

it threw this :

PhantomJS 1.9.7 (Linux) uiStateRef links2 should update the href when uiSref changes FAILED
    TypeError: 'undefined' is not an object (evaluating 'ref.match')
        at parseStateRef (/home/pgu/works/git/ui-router/src/stateDirectives.js:2)
        at /home/pgu/works/git/ui-router/src/stateDirectives.js:87
        at nodeLinkFn (/home/pgu/works/git/ui-router/lib/angular-1.0.8/angular.js:4583)
        at compositeLinkFn (/home/pgu/works/git/ui-router/lib/angular-1.0.8/angular.js:4191)
        at publicLinkFn (/home/pgu/works/git/ui-router/lib/angular-1.0.8/angular.js:4096)
        at buildCustomDom (/home/pgu/works/git/ui-router/test/stateDirectivesSpec.js:92)
        at invoke (/home/pgu/works/git/ui-router/lib/angular-1.0.8/angular.js:3000)
        at workFn (/home/pgu/works/git/ui-router/lib/angular-1.0.8/angular-mocks.js:1795)
    Expected undefined to be '#/contacts/5'.
    Expected undefined to be '#/contacts/6'.

really can't help that much. though my changes do passes the current build test ✌️

@nateabele
Copy link
Contributor

The current behavior is by design. We're considering more dynamic alternatives through separate directives.

@guilbep
Copy link
Author

guilbep commented Oct 14, 2014

@nateabele Glad to help in anyway, if you could point me in the right direction for this. Meanwhile I'll use my fork even though I don't like to do that :)
May I ask why it is so ? (by design, seems counter intuitive to me at first)
Thanks for your fast response.

@guilbep
Copy link
Author

guilbep commented Oct 16, 2014

@nateabele Maybe I could write an another directive called ui-string-sref. But I still don't see what should be the alternatives? and why it should be done through an other directive? the ui-sref is already string based (meaning you extract via parseStateRef the state and the params.. I'm just using some curly braces making it dynamic and it does not brake things :) What could I do better?

@nateabele
Copy link
Contributor

@guilbep See the discussion on #395, specifically, this comment.

@nateabele nateabele closed this Mar 28, 2015
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

Successfully merging this pull request may close these issues.

2 participants