0

I am trying desperately to pass a Angular object value onto a function. The various attempts have resulted in no progress, and the only time I got it to work properly when I hard code the values.

The MVC View:

<tr ng-repeat="project in projects | filter:search:strict">
<td><span><a style="cursor:default" title="Ändra i projektet.." id="{{project.id}}" data-ng-click="opents('/EditProject/', '{{ project.id }}')">{{ project.id }}</a></span></td>

The Angular function:

$scope.opents = function (tsUrl, id) {
        alert('/EditProject/'+ $attrs);
        alert(tsUrl);
        alert(id);
        alert(tsUrl + id);
        TINY.box.show({ url: tsUrl + id });
    };

I've tried to recieve different values from the invoke in the view, hence the many alerts. Can't find a solution for this from the web and hope someone knows of a solution.

1
  • You can not set any JS code in your ng-click. Typically "alert" does not work. It is a specific JS minimalist processor served by Angular. The angular way is to embed Jquery or any external code in a directive. Otherwise is it not taken into account during the angular digest, and your ng-repeat is not aware of you DOM changes outside of a directive... Commented Oct 1, 2014 at 9:24

2 Answers 2

2

Try:

ng-click="opents('/EditProject/', project.id)"
Sign up to request clarification or add additional context in comments.

7 Comments

Please help to understand me what do you mean :) docs.angularjs.org/api/ng/directive/ngClick
I just now used a HttpUtility to pass {{ project.id }} to get the proper convertion when invoking the function. So it gets it into a javascript string. Now the problem is the function itself is not receiving that value but instead the text {{ project.id}}, so problem remains... :-)
project.id should be passed to opents without quites and without {{ symbols. Can you update the code?
that unfortunately doesnt. If you saw my previously answer I checked the wrong property...sorry :-)
Thing is, that contents of ng-click="..." is being evaluated as usual Javascript, no additional {{, neither encoding needed. And "project" variable also acts as usual JS variable. Just update the code to see why it's not working :) Or even better try using JSFiddle? jsfiddle.net
|
0

UPDATE:

From the view I used $event instead.

ng-click="opents('/PopUp2/EditProject/', $event)

and in the function:

$scope.opents = function (tsUrl, e) {
        var id = e.currentTarget.innerText;
        TINY.box.show({ url: tsUrl + id });

and got a functional respons. Hope this helpt someone else!

1 Comment

That's a pretty tricky approach. I wonder why does not it work with just ng-click="opents('/PopUp2/EditProject/',project)" and then $scope.opents = function(tsUrl,model) { var id = model.id; ... ?

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.