How to eliminate spaces in URL scope variable - angularjs

I want to create a URL with parameters with my Angular scope variables like this:
<tr ng-repeat="tag in videocontent | filter:ContentFilter">
<td><a href='/harald/?video={{tag.VideoURL}}&minute={{tag.VMinute}}&sekunde={{tag.VSecond}}' target='_blank' rel='nofollow' >{{tag.VSecond}}: </a></td>
</tr>
Unfortunately, the final URLs contain spaces and do not work. How can I get rid of them?
Thank you,
Benjamin

Thank azium, problem solved with:
tag.whatever = tag.whatever.replace(' ', '')

Related

how to call a value from array in AngularJS controller?

I have an array like this:
$scope.persons = [{name:'Joey', age:'27'}]
I can call the value in HTML in this way
{{person.name}}
But when I try something like this, it fails
$scope.name = $routeParams.person.name
I could read the person only (without .name), it will be displayed as an array.But I want to access to the name key. Thx in advance.
I pass the person to JS in this way (route)
<tr data-ng-repeat="person in persons">
<td headers="more">
Show Details
</td>
</tr>
Try below code, as you are accessing value from array, whenever you access value from array need to mention index.
$scope.name = $routeParams.persons[0].name
Try This
Show Details

Use filter to mark sensitive data for mousestats

I want to decorate some sensitive data with MouseStats comments.
Currently i'm doing it like that:
<td><!-- StartMouseStatsHide -->{{ $ctrl.payerName }}<!-- EndMouseStatsHide --></td>
but there are plenty of sensitive data in many places of interface, so i tried to use a filter to decorate the value
<td>{{ $ctrl.payerName|mousestats_hide }}</td>
Filter simply surrounds value with comments.
The problem is that in that way comments are being escaped to entities.
What do you suggest?
Is it possible to do it using filters?
Is it possible to do it using filters?
Yes it is possible to prepend/append a variable using angular filters.
The problem is that in that way comments are being escaped to entities..
That is because you are directly interpolating the variable in scope with {{ $ctrl.payerName }}. It does not parse HTML tags and show the resultant string as is.
You need ng-bind-html directive to prevent the comments being escaped to entities, if you want to add HTML comments around given values.
So rather than doing
<td>{{ $ctrl.payerName|mousestats_hide }}</td>
You should do
<td ng-bind-html="$ctrl.payerName|mousestats_hide"></td>
Here's the working demo which generates the following markup.
(I'm not much of a fan of <table> so just replaced <td> with a <span>)
<body ng-controller="MainCtrl" class="ng-scope">
<span>Payer Name is: </span>
<span ng-bind-html="payerName |mousestats_hide" class="ng-binding">
<!-- StartMouseStatsHide -->Jakub Filipczyk<!-- EndMouseStatsHide -->
</span>
</body>
Noticed the use of $sce service I injected in filter ?
It is to prevent [$sce:unsafe] error that makes angular believe someone is attempting to use an unsafe value in a safe context.
Hope it helped!

Using razor syntax and angular

Is it possible to use AngularJS variable as Route Parameter in Razor Syntax like this?
<tr data-ng-repeat="job in jobs">
<td>
<a href="#Url.RouteUrl("editJob", new { id = job.JobID })">
<i class="glyphicon glyphicon-edit" style="color:#808080"></i>
</a>
</td>
</tr>
Right now I am using this.
<a href='#Url.Content("~/job/edit/"){{job.JobId}}'>
I'd say no, since Razor is rendered server side and at that time Angular variables don't exist. Meaning new { id = job.jobID } will result in { id : null }.
Your second solution is working because the angular string is concatenated right after the Razor part ends.
I recommend neither solutions because mixing multiple templates is always a bit dangerous. The way our team solves this is
pass in all razor dependencies on in a separate script block with a dynamically created constant on in the ng-init (if only used in simple cases)
only use these in your angular template
A bit like this (pseudo-code, example using ng-init)
<div ng-app="..." ng-init="config = { rootUrl: '#Url.Content("~/job/edit/")', otherValue: ''}">
...
</div>

Passing variable in ng-repeat

I have a ng-repeat loop and I want to pass a variable inside it...
<tr bindonce ng-repeat="row in elasticsearch.savedSearches | orderBy:['_id']">
<td><a ng-click="changeServices('row._id')" bo-text="row._id"></a></td>
</tr>
but it only passes the string "row._id".
changeServices('{{row._id}}')
doest work either.
Loose the '':
<a ng-click="changeServices(row._id)" bo-text="row._id"></a>
this should work:
hope it helps
You can also pick the row._id value in your controller without the need to passing it as above by doing:
id = $scope.row._id
Try this:
<a ng-click="changeServices(row._id)" bo-text="row._id"></a>
ie, remove the quotes from the 'row._id' else it would be treated as a string instead of variable.

Retrieve last numbers from URL in JSON - angularjs app

I have an angularjs app that loads in data from this JSON file:
http://www.football-data.org/alpha/soccerseasons/354/leagueTable?callback=JSON_CALLBACK
<tr ng-repeat="team in teamsList">
<td>{{$index + 1}}</td>
<td><a href="#/teams/{{team._links.team.href}}">
{{team.teamName}}
</a></td>
<td>{{team.playedGames}}</td>
<td>{{team.points}}</td>
<td>{{team.goals}}</td>
<td>{{team.goalsAgainst}}</td>
<td>{{team.goalDifference}}</td>
</tr>
However in this part of the code: <td><a href="#/teams/{{team._links.team.href}}"> which loads in URL eg. http://api.football-data.org/alpha/teams/61 I want to retrieve the last numbers at the end, they could be longer than 2 or less, instead of the whole URL. So anything after that last /, is there a way I could do this?
Looks like you want to write a filter like this one: Substring in Angularjs using filters?
If it's always two digits, you could get away with this:
<a href="#/teams/{{team._links.team.href|limitTo:-2}}">

Resources