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

angularjs ng-view can't load template #1314

Closed
raitucarp opened this issue Nov 15, 2013 · 17 comments
Closed

angularjs ng-view can't load template #1314

raitucarp opened this issue Nov 15, 2013 · 17 comments
Milestone

Comments

@raitucarp
Copy link

When I use angularjs, with templateUrl in routeprovider, it can't load the template into view, but I checked the logs, the xmlhttprequest to template is serves as well. Why this happens?

@szwacz
Copy link

szwacz commented Nov 15, 2013

I'm using Angular views with NW and never had any problem.
Could you provide some actual code?

@raitucarp
Copy link
Author

I apologize for my slow response..

For the sake of example-rule, I will attach myApp example, that contains minimum angularjs code.

https://www.dropbox.com/s/wn4onu602w0kt9q/myApp.zip

My environment:

  • windows xp (win32)
  • angularjs 1.2.6
  • jquery

After you extract it.. Try running it as default, in commandline: nw myApp

  • when I go to index, which is use partials template from script tag, it is fine
  • when I go to v1, and v2 it is done load the template views, but nothing happened
  • when I go to v3, which is use partials template from script tag, it is fine

angular-nw-issue

I think it's weird for me. And hard to manage views via script tag, rather than separate location as file.

@raitucarp
Copy link
Author

@szwacz @rogerwang

I summon both of you. And I apologize for my slow response

@szwacz
Copy link

szwacz commented Dec 29, 2013

Indeed it doesn't work. I'm using file:// protocol, not app:// so haven't experienced this issue.

The problem actually affects $http directive:
(inject this to app.js file provided by @raitucarp)

app.controller('indexCtrl', function ($scope, $http) {
    $scope.hello = 'Hello world';

    $http.get("/app/views/v1.html").then(function (response) {
        // success event should fire....
        console.log('$http ok');
        console.log(response);
    }, function (err) {
        // ...but error will fire instead
        console.log('$http error');
        console.log(err);
    });

});

In angular $http directive is failing, because it is checking status code of HTTP response like so:

function isSuccess(status) {
  return 200 <= status && status < 300;
}

XMLHttpRequest is returning status code 0 (zero), when used with file:// protocol, and this behaviour was copied to app:// protocol, what leads to $http fail.

Solution is simple: XMLHttpRequest in node-webkit should return status code 200 instead of 0 when used with app:// protocol.

Please reopen this issue.

@raitucarp
Copy link
Author

Hmm okay

Should we mention angular developer here? Or just create new issue there and link this issue?

@szwacz
Copy link

szwacz commented Dec 29, 2013

This issue should be resolved on node-webkit side. Angular is standards compliant, node-webkit is not (returns invalid status code).

@raitucarp
Copy link
Author

Is angular supports app:// protocol or not? I just want use app protocol not file protocol, actually. What should I do?

@szwacz
Copy link

szwacz commented Dec 29, 2013

app:// protocol can be found only in node-webkit, and was born to easily port websites into desktop apps. Angular doesn't even know such thing as app:// exist.

You should wait for patch in NW.

@szwacz
Copy link

szwacz commented Dec 29, 2013

It turns out you can also easily patch your local angular.js file (use not-minified version).
Find line:

// fix status code for file protocol (it's always 0)
status = (protocol == 'file' && status === 0) ? (response ? 200 : 404) : status;

And change it to:

// fix status code for file protocol (it's always 0)
status = ((protocol == 'file' || protocol == 'app') && status === 0) ? (response ? 200 : 404) : status;

Although this is really simple to fix in angular I will repeat: app:// protocol is internal to NW, and nothing except NW should know about its existance.

@raitucarp
Copy link
Author

Ok thanks. That is maybe the only solution. 👍

But, I think Angular.js team should know about this. Because for future use It's important, that html5+js technology is moving forward, never backward.

@raitucarp
Copy link
Author

Oh okay, now, I know that this is not angular problem. I apologize my previous comment.

This issue happens because chrome not allowing xmlhttprequest from other protocol except http. @rogerwang should read this.

@rogerwang
Copy link
Member

thanks for reporting. I'll fix it.

@tomasdev
Copy link

👍

So to fix this NW should return valid status code (200) when XMLHttpRequest was used with app:// protocol.

@rogerwang do we have an estimate on when this can be fixed?

Otherwise feel free to let us know where to modify the response status to do a PR if protocol is app://

@rogerwang
Copy link
Member

I'll try to fix this in next version 0.9.2. Thanks.

@rogerwang rogerwang added this to the 0.9.2 milestone Feb 13, 2014
@tomasdev
Copy link

❤️ ❤️ ❤️

rogerwang added a commit that referenced this issue Feb 21, 2014
Fix #1314

Conflicts:
	src/net/app_protocol_handler.cc
@cmarrero01
Copy link

This actually happen on 0.11.0, How I fix it?

#2643

@cmarrero01
Copy link

I fix this with this code:

 $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|chrome-extension|app):/);
 $compileProvider.imgSrcSanitizationWhitelist(/^\s*(https?|ftp|mailto|chrome-extension|app):|data:image\//);

For more information about this, read : https://docs.angularjs.org/api/ng/provider/$compileProvider

:)

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

5 participants