Issue
I have the following markup that shows a value from ng-model:
<a ng-click="downloadDocument()">{{document.content.replace(/\d+\_/,"")}}</a>
Before each document.content
I add a number and an underscore, something like "12122141_document.txt"
. I want to replace this part by using the regex /\d+\_/
.
This throws an error in AngularJS, although {{ document.replace(" ","") }}
works.
Is the only way to solve this a directive or am I doing something wrong?
Solution
I modified your Plunker-Demo and it works pretty fine.
Hint: Don't use $scope
namespaces like "document". Its reserved/used by the client.
var app = angular.module('plunker', []);
Controller
app.controller('MainCtrl', function($scope) {
$scope.name = 'World';
$scope.fileName = {
content : function(){
return '1233_test.txt'.replace(/\d+\_/,"");
}
}
$scope.mpla = function () {
console.log('clicked');
}
});
View
<!DOCTYPE html>
<html ng-app="plunker">
<head>
<meta charset="utf-8" />
<title>AngularJS Plunker</title>
<script>
document.write('<base href="' + document.location + '" />');
</script>
<link rel="stylesheet" href="style.css" />
<script data-require="angular.js@1.3.x" src="https://code.angularjs.org/1.3.14/angular.js" data-semver="1.3.14"></script>
<script src="app.js"></script>
</head>
<body ng-controller="MainCtrl">
<p>Hello {{name}}!</p>
<a ng-click="mpla()" ng-bind="fileName.content()"></a>
</body>
</html>
Answered By - lin
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.