Marko
Marko

Reputation: 1401

Angular Select: build string

I want to build a url where parts of the url string are dynamic build with a select box.

The watch is only called at startup:

$scope.$watch('url', function () {
    $scope.buildUrl();
}, true);

Here is the fiddle:

http://jsfiddle.net/mkeuschn/wJGFm/

best regards

Upvotes: 0

Views: 269

Answers (1)

Davin Tryon
Davin Tryon

Reputation: 67316

The $watch will only fire if the value being watched changes. In this case, it is better to watch dimension, since this is the selection that is changing. Then, you can re-assign the dimension part of the url and re-build.

Here is an updated fiddle.

JS:

$scope.buildUrl = function () {
    $scope.url.dimension = $scope.dimension.value;
    $scope.completeUrl = $scope.url.base + "dateFrom=" + $scope.url.from + "&dateTo=" + $scope.url.to + "&dimension=" + $scope.url.dimension;
};

$scope.$watch('dimension', function () {
    $scope.buildUrl();
}, true);

Upvotes: 1

Related Questions