// Declare app level module which depends on filters, and services
angular.module('myApp', ['myApp.directives'])
.controller('PasteController', ['$scope', function ($scope) {
$scope.rawPaste = '';
$scope.parsedPaste = [];
}]);
angular.module('myApp.directives', [])
.directive('angularPaste', ['$parse', '$document',
function ($parse, $document) {
return {
restrict:'E',
link:function (scope, element, attrs) {
//We do not want to eat up chars if some text box is focussed
//this variable will be set to true if focus is currently on
//a textbox
var inFocus = false;
function parseTabular(text) {
//The array we will return
var toReturn = [];
try {
//Pasted data split into rows
var rows = text.split(/[\n\f\r]/);
rows.forEach(function (thisRow) {
var row = thisRow.trim();
if (row != '') {
var cols = row.split("\t");
toReturn.push(cols);
}
});
}
catch (err) {
console.log('error parsing as tabular data');
console.log(err);
return null;
}
return toReturn;
}
function textChanged() {
var text = $('#myPasteBox').val();
if (text != '') {
//We need to change the scope values
scope.$apply(function () {
if (attrs.ngModel != undefined && attrs.ngModel != '') {
$parse(attrs.ngModel).assign(scope, text);
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.