0

this first part working fine.

<div ng-app="" ng-init="mySwitchone=true">
<p>
    <button ng-disabled="mySwitchone">Click Me!</button>
</p>
<p>
    <input type="checkbox" ng-model="mySwitchone"/>Button
</p>
<p>
{{ mySwitchone }}
</p>
</div>

But do not work on second part. What's wrong with this code. Can anyone tell me.

<div ng-app="" ng-init="myTest=true">

<p>
    <button ng-disabled="myTest"> Click me</button> 
</p>
<p>
    <input type="checkbox" ng-model="myTest"/>Button
</p>
<p>
    {{ myTest }}
</p>

</div>
6
  • It does work? jsfiddle.net/b6yjgfvz/1 Commented Aug 17, 2015 at 13:51
  • Any error in console? Commented Aug 17, 2015 at 13:52
  • No error in console. I want to work both part one html page. But first part work fine. but second part not work. Commented Aug 17, 2015 at 13:55
  • 3
    You have both div in the same page ? If yes, remove ng-app on the second div. You can't declare this multiple times. Commented Aug 17, 2015 at 13:58
  • 3
    @RejithRKrishnan aha I see. The problem is that you have multiple ng-app on one page. It can be solved by doing this. jsfiddle.net/b6yjgfvz/3 Commented Aug 17, 2015 at 13:59

2 Answers 2

2

First problem you can use multiple ng-app. Try this bellow way

<!DOCTYPE html>
<html ng-app="">
<body>


<div  ng-init="mySwitchone=true">
<p>
    <button ng-disabled="mySwitchone">Click Me!</button>
</p>
<p>
    <input type="checkbox" ng-model="mySwitchone"/>Button
</p>
<p>
{{ mySwitchone }}
</p>
</div>

<div  ng-init="myTest=true">

<p>
    <button ng-disabled="myTest"> Click me</button> 
</p>
<p>
    <input type="checkbox" ng-model="myTest"/>Button
</p>
<p>
    {{ myTest }}
</p>

</div>


</body>
</html>

See more

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

1 Comment

Linking to w3schools is generally a poor resource, linking to docs.angularjs.org/api/ng/directive/ngApp or some better resource would be much more helpful.
1

This is how your code needs to be-

<div ng-app="" ng-init="mySwitchone=true;myTest=true">
<p>
<button ng-disabled="mySwitchone">Click Me!</button>
</p>
<p>
<input type="checkbox" ng-model="mySwitchone"/>Button
</p>
<p>
{{ mySwitchone }}
</p>

<p>
<button ng-disabled="myTest"> Click me</button> 
</p>
<p>
<input type="checkbox" ng-model="myTest"/>Button
</p>
<p>
{{ myTest }}
</p>

</div>

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.