reading a viarble in the document

时间:2018-03-09 19:07:01

标签: javascript angularjs

This seems like it should be simple i have a menu using Angular that sets a variable "active"

<a class="about" href="#" ng-click="active='About Me'">About Me</a>

and a Paragraph that will output whatever that active name is

<p ng-show="active">You chose <b>{{active}}</b></p>

What i can't figure out is now to set up a if check wither if "$active/{{active}} = "about me"" display this block of code so each link will fill the body with different content.

Any thoughts?

1 个答案:

答案 0 :(得分:0)

To achieve expected result, use below option
HTML:

<div ng-app="test" ng-controller="testCtrl">
<a class="about" href="#" ng-click="active='About Me'">About Me</a>
  <a class="about" href="#" ng-click="active='Home'">Home</a>
<p ng-show="active">You chose <b>{{active}}</b></p>
</div>

JS:

var app = angular.module('test',[]);

app.controller('testCtrl',function($scope){

})

Make sure that the active scope variable is inside the tag having controller

code sample- https://codepen.io/nagasai/pen/wmBMjd