-1

I need to create a method to compone a url, So in my class I do this:

createLink take un id and return the url:

console.log("before the method");
console.log($scope.createLink )
$scope.createLink = function createLink (id) {
    
    var link = url+ '?idA=' + id;
    return link;
};
console.log("after method ");
console.log($scope.createLink );

this is my html page:

<a ng-href="{{ createLink (file.id) }}" target="_blank" ><i

The problem is that when the console prints me the "after the method value", I doesn't read the correct value (like /user/donwlo....), but the console.log prints me the method:

function createLink (id) {
        
        var link = urlDownloadAllegatoDettRend + '?idA=' + id;
        return link;
    };

lie value of $scope.createLink;

Anyone can help me to resolve this problem?

1 Answer 1

0

You should either console.log(link) inside the createLink function before you return. Like this:

function createLink (id) {   
        var link = url + '?idA=' + id;
        console.log(link);
        return link;
};

or console.log($scope.createLink()) to invoke the function to run again and inside there you can also pass whatever id you want. Like such:

$scope.createLink = function createLink (id) {
    var link = url + '?idA=' + id;
    return link;
};
console.log("after method ");
console.log($scope.createLink("example"));

Now about your href element, it should work as long as the url variable is in the scope so javascript can recognize the value and is not undefined. If you want the same url beginning that you already have, you don't need the url variable.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.