好吧,我有主头控制器,我有这个:
<div class="fade-show-hide" ng-class="{'ng-hide':loggedInClose==true}" ng-show="loggedInOpened" ng-cloak>
@Html.Partial("~/Views/Shared/_LoggedInPartial.cshtml")
</div>
Run Code Online (Sandbox Code Playgroud)
在脚本我有这个:
$ scope.loggedInClose = false;
$scope.toggleLoggedIn = function () {
$scope.loggedInOpened = !$scope.loggedInOpened;
$scope.languagesOpened = false;
$scope.loginOpened = false;
};
Run Code Online (Sandbox Code Playgroud)
问题是当我使用这个代码没有发生任何事情...我得到$scope.loggedInClose = true;但div不隐藏...
angular.element(document).on('click', function () {
$scope.loggedInClose = true;
});
Run Code Online (Sandbox Code Playgroud)
如果我点击页面上的任何地方,有人可以解释我如何隐藏div吗?
我的问题如下。我应该避免在Angular应用程序中使用任何种类的jQuery代码,因为与DOM交互只有一件事是合法的。另一个问题是,是否有人遇到除了使用jQuery编写快速hack之外找不到其他解决方案的问题。
谢谢!
我想在输入中按Enter时触发按钮的单击事件,我发现使用AngularJS非常困难.
我的观点(简化,更新):
<!doctype html>
<html lang="en" ng:app="test">
<head>
<meta charset="utf-8" />
<title>Test</title>
<link rel="stylesheet" href="css/app.css" />
</head>
<body ng-controller="TestController">
<button ng-click="onButton1Click()" class="btn1">Click Me</button>
<button ng-click="onButton2Click()" class="btn2">Don't click me</button>
<script src="lib/jquery/jquery.js"></script>
<script src="lib/angular/angular.js"></script>
<script src="js/testcontroller.js"></script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我对此视图的控制器:
'use strict';
angular.module('test', [])
.controller('TestController', ['$scope',
function($scope) {
$scope.onButton1Click = function() {
alert("Hello");
}
$scope.onButton2Click = function() {
$('.btn2').click();
}
}])
Run Code Online (Sandbox Code Playgroud)
我简化了所有代码.当我点击btn2时,我收到此错误
$申请已在进行中
不,我不能$scope.onButton1Click()直接打电话,我必须模拟btn1点击.
我是AngularJS的新手.我必须为视频播放器(HTML5 <video>)创建海关控制.基本上,我会使用getElementById('myvideotag'),听取视频点击播放/暂停.我如何使用AngularJS做到这一点?将点击绑定ng-click="videoPlayPause()"但随后,我如何播放或暂停视频.我如何使用经典方法<video>?
我想这很简单......我还没有得到所有的AngularJS概念!
谢谢 :)
哦,代码......在视图中:
<video autoplay="autoplay" preload="auto" ng-click="video()">
<source src="{{ current.url }}" type="video/mp4" />
</video>
Run Code Online (Sandbox Code Playgroud)
在正确的控制器中:
$scope.video = function() {
this.pause(); // ???
}
Run Code Online (Sandbox Code Playgroud) 我想在角度应用程序中使用jquery的UI布局插件.是否有角度指令已经执行此操作,或用于相同的目的?
在Swift中编写简单的字数统计函数有什么更优雅的方法?
//Returns a dictionary of words and frequency they occur in the string
func wordCount(s: String) -> Dictionary<String, Int> {
var words = s.componentsSeparatedByString(" ")
var wordDictionary = Dictionary<String, Int>()
for word in words {
if wordDictionary[word] == nil {
wordDictionary[word] = 1
} else {
wordDictionary.updateValue(wordDictionary[word]! + 1, forKey: word)
}
}
return wordDictionary
}
wordCount("foo foo foo bar")
// Returns => ["foo": 3, "bar": 1]
Run Code Online (Sandbox Code Playgroud) 我是AngularJS的新手,想要为点击"忘记密码"链接时的登录页面创建类似于此处的功能:
http://bootsnipp.com/snippets/featured/login-amp-password-reminder#comments
是否最好使用指令,因为这是行为,而不是控制器?我已经为它创建了一个控制器,但是当我在这个主题上搜索帮助时,我发现使用控制器可能不是这样的.这是我最近的试验不成功(链接在点击时没有任何作用):
在js文件的控制器端:
angular.module('mean.users')
.controller('SwitcherCtrl', ['$document',
function($document) {
$document.ready(function () {
$document.getElementById('olvidado').click(function (e) {
e.preventDefault();
$document.getElementById('form-olvidado').toggle('500');
});
$document.getElementById('acceso').click(function (e) {
e.preventDefault();
$document.getElementById('form-olvidado').toggle('500');
});
});
}
])
Run Code Online (Sandbox Code Playgroud)
在HTML方面,我在必要时包括ng-controller ="SwitcherCtrl".
试图找到构建Angular App的"最佳"方法我找到了几篇最佳实践文章.有了这个输入,我做了这个:
angular.module('xApp', [])
//..... some services, factories, controllers, ....
.directive('dirNotification',[ function dirNotification() {
return {
scope: {},
templateUrl: 'xNotification.html',
replace: true,
controller: 'CtrlNotification',
link: function($scope){
// if this is 'DOM manipulation, should be done here ... ?
/*
$scope.$on('session.update',function(event, args) {
if (args == null) {
$scope.notificationdata.username = "";
$scope.notificationdata.sid = "";
} else {
$scope.notificationdata.username = args.username;
$scope.notificationdata.sid = args.accessToken;
}
});
*/
}
};
}])
.controller('CtrlNotification',['$scope' ,function CtrlNotification($scope) {
$scope.notificationdata = {
username: "",
sid: ""
}; …Run Code Online (Sandbox Code Playgroud) 我确定这个问题已经以一种或另一种形式得到了无数次的回答,但是我不确定要寻找什么才能找到解决方案。
假设我们有一个简单的ng-repeat:
<div ng-repeat="item in items">
<input type="text" value="{{item.name}}">
<a ng-click="getTxtBoxVal(whatDoIPassInHere)">Get Text Box Value</a>
</div>
Run Code Online (Sandbox Code Playgroud)
在javaScript文件中:
function $scope.getTxtBoxVal(val) {
alert(val)
}
Run Code Online (Sandbox Code Playgroud)
基本上我想知道应该在whatDoIPassInHere参数中传递什么,在jquery中将是这样的:$(this).siblings(input).val()
我确实有一种解决方法,即为每个文本框赋予唯一的ID:
<input type="text" id="myTextBox_{{index}}" value="{{item.name}}>
并使用唯一的ID定位它,但是我敢肯定,有一种更优雅的方式来处理此问题
我试图在完整页面加载后运行一个小的jQuery片段,但是即使在完全加载页面之后也没有呈现一些AngularJS代码.
jQuery在页面加载后在控制台中工作.
这是我正在尝试的jQuery:
jQuery("a:contains('Clone')").parent().parent().parent().prepend(jQuery("#clone_external"));
但它仍然没有发生
克隆按钮不是普通按钮,而是角度按钮
`<div ng-init="projectPath='projects.srk_test_pro_ject';artifactId='artf3596';folderId='tracker1787';folderPath='projects.srk_test_pro_ject/tracker.ACR';returnUrlKey='1494858605684';hasCreatePermission='true'" data-ng-include="'/ctf/js/saturn/tracker/cloneArtifact.html'" ng-bindable="" class="Middle ng-scope"><div data-ng-controller="CloneCtrl" class="ng-scope"><a href="#" data-ng-show="!disableCloneBtn" data-ng-click="clone()" data-i18n-content="{bundle: 'tracker', key: 'clone/label'}" class="">Clone</a></div></div>`
Run Code Online (Sandbox Code Playgroud)
我试过文件准备好并加载在一起,但仍然没有运气
jQuery(document).ready(function() {
jQuery(window).load(function() {
jQuery("a:contains('Clone')").parent().parent().parent()
.prepend(jQuery("#clone_external"));
});
});
Run Code Online (Sandbox Code Playgroud)
我更喜欢javascript/jQuery解决方案而不是角度解决方案.