Problema with ng-click function

Gonzalo

I am trying to make a product configurator for a website. I'm using MEAN but at this point I just have a problem with AngularJS.

I proceed to explain my program. In the application you have three buttons for the first step of the configuration.

When you click one, AngularJS send back to the web the next three buttons (the values of this buttons depends on the first one you click). And here arrives the problem, this last buttons doesnt seems to work.

After clicking the first button I call the function $scope.getOption2 and it returns this:

htmlsString= '<div><button id="btnS2-1" ng-click= getOption3(1)>1</button></div>'+
             '<div><button id="btnS2-2" ng-click= getOption3(2)>2</button></div>'+
             '<div><button id="btnS2-3" ng-click= getOption3(3)>3</button></div>';        

And this is the way I print it on screen: $scope.option2 = $sce.trustAsHtml(pruebaHTML);

But the function $scope.getOption3 is never called when I click in one of those buttons.

I have simplified the code, but the essential part is here. I hope somebody can see my problem.

Andreas

Appending elements like this is not the Angular way, and is frowned upon. Angular does not know of your new buttons, because you cannot manipulate your DOM in this way. You could $compile your elements again, but maybe you should just have the buttons in your template to begin with, you could show them with ngShow. Maybe better yet, see if there is some directive out there that can do what you want - or roll your own.

Look http://docs.angularjs.org/api/ng.$compile for details on $compile.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Define a function for ng-click in an Angular directive

분류에서Dev

How to pass an AngularJs ng-click function on a button?

분류에서Dev

ng-click wont trigger, function not working. Could it be scope?

분류에서Dev

click and re-click function within click function

분류에서Dev

On click function not working

분류에서Dev

jQuery click(function) not working

분류에서Dev

If statement and .click function

분류에서Dev

click button at end of function

분류에서Dev

ng-click within an ng-repeat, not formatting values correctly

분류에서Dev

angularjs ng-click and href on anchor

분류에서Dev

Dynamic variable for angular ng-click attribute

분류에서Dev

Weird behaviour with angularjs ng-click

분류에서Dev

Common directive ng-click guidance needed

분류에서Dev

AngularJS - Sliding down menu on ng-click

분류에서Dev

ng-click not working when button is pushed

분류에서Dev

ng-click not working in AngularJS, Cordova

분류에서Dev

Ionic / Angular ng-click for select input

분류에서Dev

ng : click과 ng-click의 차이점은 무엇입니까?

분류에서Dev

Focusout function negates submit on click

분류에서Dev

Click function executed on page load

분류에서Dev

Function onSelect is faster than click

분류에서Dev

Angularjs ng-click-active class for anchor tags

분류에서Dev

ng-click으로 $ http GET 호출

분류에서Dev

ng-hide show on-click event in AngularJS

분류에서Dev

Remove click event on last item in ng-repeat

분류에서Dev

ng-click doesn't take parameters from the DOM

분류에서Dev

AngularJS: Template-added ng-click does not fire

분류에서Dev

Angularjs keep the focus on a field after ng-click?

분류에서Dev

how to toggle class in angular js on ng-click