Angular切换不工作
Angular Toggle not Working
我试图将以下内容转换为Angular方法,但我被卡住了:
HTML:<div id="container" class="container">
<embed src="www.example.com/pdf1" width="500" height="500" type='application/pdf' id="myPdf">
<embed src="www.example.com/pdf2" width="500" height="500" type='application/pdf' id="myPdf2">
</div>
<div class="container">
<button class="btn-info" onclick="toggle('myPdf2')" type="button">Toggle PDF</button>
</div>
JavaScript: function toggle(target) {
var curVal = document.getElementById(target).style.visibility;
document.getElementById(target).style.visibility = (curVal === 'visible') ? 'hidden' : 'visible';
};
基本上它是一个开关,它使一个pdf的出现和消失。
有人建议我采取以下有角度的方法:
<button ng-click="isShown = isShown ? false : true" type="button">Toggle</button>
<div id="container" class="container">
<embed src="www.example.com/pdf1" width="500" height="500" type='application/pdf' id="myPdf">
<embed ng-show="isShown" src="www.example.com/pdf2" width="500" height="500" type='application/pdf' id="myPdf2">
</div>
由于某些原因,Angular的方法不适合我。
您需要在两个pdf上设置ng-show
指令。isShown = isShown?false:true
也可简化为isShown = !isShown
试试这个:
<html ng-app>
<body ng-controller="mianController">
<button ng-click="isShown = !isShown" type="button">Toggle</button>
<div id="container" class="container">
<embed ng-show="!isShown" src="www.example.com/pdf1" width="500" height="500" type='application/pdf' id="myPdf">
<embed ng-show="isShown" src="www.example.com/pdf2" width="500" height="500" type='application/pdf' id="myPdf2">
</div>
<body>
</html>
JavaScript
angular.module([]).controller('mainController', function($scope){});
相关文章:
- 我的shareService在angular 2中发送值工作正常,但当我渲染我的另一个组件时,会获得默认值
- 为什么不是'我的函数在解析云代码中工作吗?当我在Angular和Express中测试时,它是有效的
- 注入工厂时,Angular停止工作
- Angular Js布线工作不正常
- 代码在angular中未按预期工作
- Angular JS-视图不工作
- angular js应用程序不工作
- grunt serve:dist时找不到Angular.js模块,但grunt serve工作正常
- 带有Angular指令的HTML;附加时无法工作
- 2D数组在Angular JS 1.2.x中工作,而不是在1.3.x中工作
- 如何使Angular JS控制器与指令一起工作
- $scope$Angular中的手表;我不在爱奥尼亚/科尔多瓦工作
- 让typescript与facebook登录为Angular 2项目工作
- 提前输入以在 Angular 模板中工作
- 最基本的 Angular 应用程序无法正常工作
- Angular 的新手 - 在 eclipse 中的设置无法正常工作
- 与 Angular 1.5 的单向数据绑定类似于双向工作
- 使用 Angular 和 UI-bootstrap 对模态事件绑定无法工作的指令
- Angular ng sortable-如果我在一个栏中添加了一个搜索框,则拖放在两列之间无法正常工作
- 我的$asyncValidator不工作-Angular Javascript