Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do navigation in a chrome packaged app using angular.js?

I'm experimenting with chrome packaged apps, my first screen has a list of items, when i click on an item, a detail page should be visible.

I a normal web app you just do:

<a href="#/detail/{{item.name}}">{{item.name}}</a>

But in a packaged app i get the following error:

Can't open same-window link to "unsafe:chrome-extension://fsdjiojkljkljdfijkjkijkjkjijikf/index.html#/detail/blablabla"; try target="_blank".

So how do i do some kind of navigation in a chrome packaged app?

Thanks

like image 556
cremersstijn Avatar asked Nov 16 '13 11:11

cremersstijn


People also ask

Can we use angular for Chrome extension?

You can find Angular DevTools in the Chrome Web Store and in Firefox Addons. After installing Angular DevTools, find the extension under the Angular tab in your browser DevTools. Lets you explore the components and directives in your application and preview or edit their state.

What is $location in AngularJS?

Overview. The $location service parses the URL in the browser address bar (based on the window. location) and makes the URL available to your application. Changes to the URL in the address bar are reflected into $location service and changes to $location are reflected into the browser address bar.

How can you integrate AngularJS with HTML?

AngularJS extends HTML with ng-directives. The ng-app directive defines an AngularJS application. The ng-model directive binds the value of HTML controls (input, select, textarea) to application data. The ng-bind directive binds application data to the HTML view.


1 Answers

As pointed by @romario333, see https://stackoverflow.com/a/15769779/122441 :

You need to explicitly add URL protocols to Angular's whitelist using a regular expression. Only http, https, ftp and mailto are enabled by default. Angular will prefix a non-whitelisted URL with unsafe: when using a protocol such as chrome-extension:.

A good place to whitelist the chrome-extension: protocol would be in your module's config block:

var app = angular.module( 'myApp', [] )
.config( [
    '$compileProvider',
    function( $compileProvider )
    {   
        $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|chrome-extension):/);
        // Angular before v1.2 uses $compileProvider.urlSanitizationWhitelist(...)
    }
]);

The same procedure also applies when you need to use protocols such as file: and tel:.

Please see the AngularJS $compileProvider API documentation for more info.

like image 72
Hendy Irawan Avatar answered Oct 29 '22 16:10

Hendy Irawan