0

This html code :

<md-button class="md-primary " ng-click="setDevice('phone')">Phone           
        </md-button>
<md-button class="md-primary " ng-click="setDevice('tablet')">
           Tablet
        </md-button>

<div class="area-{{setDevice}}">
    <me-iphone tmp-url="{{appTemplateUrl}}"></me-iphone>
</div>

First Time When Click Phone or Tablet Button Update setDevice Value

$scope.setDevice = "";
$scope.setDevice = function(setDevice){
            $scope.setDevice = setDevice;
        }

The problem is (First Click phone), When Click Tablet Button Not update setDevice Value

When click both button, hope to update $scope.setDevice Value

2 Answers 2

4

Although, your line of thinking is correct, you've messed it up a little bit in syntax. :) Which is okay and an essential step in learning.

In your code, you have declared your setDevice, first, as a string and then as a function. Becuase the last assignment is a function, your $scope.setDevice is no longer a string, but a function.

Change the name of the variable to something else and it will work fine.

$scope.currentDevice = "";
$scope.setDevice = function(setDevice){
    $scope.currentDevice = setDevice;
}

And in your HTML

<md-button class="md-primary " ng-click="setDevice('phone')">Phone</md-button>
<md-button class="md-primary " ng-click="setDevice('tablet')">Tablet</md-button>

<div class="area-{{currentDevice}}"> <!-- THIS NEEDS TO BE UPDATED AS WELL -->
    <me-iphone tmp-url="{{appTemplateUrl}}"></me-iphone>
</div>
Sign up to request clarification or add additional context in comments.

4 Comments

New post when I was about to answer pretty much the same. +1
Update "currentDevice" Value But not refresh div tag. What can I do that?
What do you mean But not refresh div tag? Angular has 2 way data binding. You don't need to update/refresh tags (DOM) :)
Your are correct. I double checked my code, There was syntax error. I fixed that. It's now working. Thanks you for reminded me this idea about angular js.
0

Use your code just like this:

$scope.setDevice = function(setDevice){
   return setDevice;
}

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.