Created
April 14, 2014 02:59
-
-
Save chrishowes/10612759 to your computer and use it in GitHub Desktop.
AngularJS, Chrome Extensions, and CSP issues (ngClick, ngKeypress, etc.)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This bit of code doesn't work: | |
<div ng-controller="MainCtrl" ng-csp> | |
<input type="text" ng-click="clickFunction()"> | |
</div> | |
function MainCtrl($scope) { | |
$scope.clickFunction = function(event) { console.log(event); } | |
} | |
I think it has to do with ng-csp and this not allowing you to execute JS on the main page of a chrome extension. | |
This blocks me from using ALL angular directives with an eval (ng-click, ng-keypress, etc.) | |
My "hacky" workaround: | |
<input type="text" ng-enter> with: | |
app.directive('ngEnter', function($rootScope) { | |
return { | |
link: function(scope, element, attrs) { | |
element.bind("keypress", function(e){ | |
// logic | |
$rootScope.$broadcast(ENTER_RECIEVED, true); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment