我有以下2个函数/类
function Availability(){
this.Click = function (){
alert("Availability");
}
}
function Help(){
this.Click = function (){
alert("Help");
}
}
Run Code Online (Sandbox Code Playgroud)
我创建了以下模块:
var Gadgetory = angular.module("Gadgetory", []);
Run Code Online (Sandbox Code Playgroud)
和以下控制器:
var ToolbarController = Gadgetory.controller('ToolbarController', ['$scope',
function ($scope)
{
$scope.greeting = 'Gadgetory!';
$scope.Gadgets = [
{ name: "Availability", icon: "available.png", object: new Availability() },
{ name: "Help", icon: "help.png", object: new Help() }
];
}
]);
Run Code Online (Sandbox Code Playgroud)
现在在我的html中,我想调用字典中每个小工具的click方法,如下所示:
<div ng-repeat="gadget in Gadgets">
<img ng-src="/Gadgets/{{gadget.icon}}" ng-click="{{gadget.object}}.Click()"/>
</div>
Run Code Online (Sandbox Code Playgroud)
但这不起作用,你能帮帮我吗?
我有一个外部控制器,在其视图内包含一个指令.该指令获取一个过程点列表并生成链接,您可以在其中选择每个过程点.它在链接函数中正确设置HTML,但链接的ng-click操作不起作用.
有任何想法吗?:)
非掠夺性代码
HTML
<!DOCTYPE html>
<html>
<head><link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet">
<script src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.min.js"></script>
<script src="script.js"></script>
</head>
<body ng-app="app">
<div ng-controller="widget">
<process stages="production" at="productionAt"></process>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
JS
angular.module('app', ['app.directives', 'app.controllers']);
angular.module('app.controllers', [])
.controller('widget', function($scope) {
var selectStage = function () {
alert(this.label + " selected.");
$scope.processAt = this;
}
$scope.production = [
{label: "Starting", select: selectStage}
, {label: "Fermenting", select: selectStage}
, {label: "Pouring", select: selectStage}
, {label: "Beer!", select: selectStage}
];
$scope.productionAt = $scope.production[0];
});
angular.module('app.directives', []) …Run Code Online (Sandbox Code Playgroud) 我有一个像以下的HTML代码:
<div class="outerdiv" data-ng-click="resetText()">
<div class="innerdiv" data-ng-click="showText()">
{{ text }}
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
外部div与a ng-click和内部div具有不同ng-click.
我的问题是:当我点击内部div时,外部的div也会被触发.我能做些什么来解决这个问题(解雇内部功能,而不是外部功能?
我可以使用硬编码标志使其工作,但不确定我是否面对竞争条件问题.
这是一个说明问题的小提琴.
如何传递,也就是说,参考范围的参数,在ng-click你可以检查我在这个填充器中想要什么
我正在使用ng-click调用一个带有$ scope范围的参数的函数.不幸的是,不是从角度处理的参数或我得到此错误:
错误:[$ parse:syntax]语法错误:令牌':'不是从[:notification]开始的表达式[:notification]的第1列的主表达式.
导致错误的HTML代码段:
<div ng-click="goToNotif({{notification.id}})"></div>
Run Code Online (Sandbox Code Playgroud)
HTML代码段未从角度处理:
<div ng-click="goToNotif(notification.id)"></div>
Run Code Online (Sandbox Code Playgroud)
重要信息:notification从重复解析
<div(ng-repeat="notification in notifications")></div>
Run Code Online (Sandbox Code Playgroud) data-binding function angularjs ng-repeat angularjs-ng-click
以下是我的页面:

现在,当我点击Capture1.png时,我想首先在新标签上显示该图像,而不会弹出如上图所示.
当我点击sample.pdf时,我想首先在新标签上显示pdf.
这是我的HTML:
<div ng-controller="MyController">
<a target="_blank" href="/Account/FetchFile/{{File_Id}}" ng-click="OpenFile(File_Id)" style="line-height:20px">Capture1.png</a>
<a target="_blank" href="/Account/FetchFile/{{File_Id}}" ng-click="OpenFile(File_Id)" style="line-height:20px">sample.pdf</a>
</div>
Run Code Online (Sandbox Code Playgroud)
我的控制器:
var app = angular.module('MyController', ['ur.file', 'ngResource']);
app.controller('MyController', function ($scope, $resource, $http,$window) {
var url = "http://localhost:47000/Account/FetchFile/" + fileId;
$window.open(url, '_blank');
}
Run Code Online (Sandbox Code Playgroud)
服务器端:
public FileContentResult FetchFile(int id)
{
byte[] fileContent = null;
string fileType = "";
string fileName = "";
var file = GetFileByID(id);
if (file != null)
{
fileContent = file.Data;
fileType = file.ContentType;
fileName = file.FileName;
return File(fileContent, fileType, fileName);
} …Run Code Online (Sandbox Code Playgroud) 我有一个表,其中最后一列包含应该打开一个新窗口但不会打开新窗口的按钮.这是我的代码:
<table class="table table-hover" id="angular_table">
<thead>
<tr>
<th class="company">Nome azienda <a ng-click="sort_by('company')"><i class="icon-sort"></i></a></th>
<th class="code">Codice <a ng-click="sort_by('code')"><i class="icon-sort"></i></a></th>
<th class="projectName">Nome progetto <a ng-click="sort_by('projectName')"><i class="icon-sort"></i></a></th>
<th class="recordType">Tipo di record <a ng-click="sort_by('recordType')"><i class="icon-sort"></i></a></th>
<th class="year">Anno <a ng-click="sort_by('year')"><i class="icon-sort"></i></a></th>
<th class="month">Mese <a ng-click="sort_by('month')"><i class="icon-sort"></i></a></th>
<th>Crea ricavo </th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in items | filter:query:checkEqual | orderBy:sortingOrder:reverse " id="lista">
<td>{{item.company}}</td>
<td >{{item.code}}</td>
<td style="text-align: -webkit-left;"> <a href="/{{item.id}}" target="_blank">{{item.projectName}}</a></td>
<td>{{item.recordType}}</td>
<td>{{item.year}}</td>
<td>{{item.month}}</td>
<td class="btnCrea"><button class="btn2 btn-default2" ng-click="window.open('/apex/creaRicavoM?id={{item.id}}','_blank','heigth=600,width=600')">Crea</button></td>
</tr>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
有人能帮我吗?提前致谢!
我正在尝试制作简单的多语言网站.我有一个小控制器只是为了能够更改根范围中的当前语言:
app.controller('Ctrl', function($scope, $rootScope) {
$rootScope.currentLang = 'en_US';
$scope.switchLang = function(){
if($rootScope.currentLang ==='en_US'){
$rootScope.currentLang = 'cs_CS';
} else {
$rootScope.currentLang = 'en_US';
}
}
});
Run Code Online (Sandbox Code Playgroud)
我想将我的数据存储在过滤器中:
app.filter('ci18n', function($rootScope){
return function(id_text){
var translations = {
'en_US' : {
'GREETING' : 'Hi'
},
'cs_CS' : {
'GREETING' : 'Cau'
}
};
return translations[$rootScope.currentLang][id_text];
};
});
Run Code Online (Sandbox Code Playgroud)
问题是我的网站不会随rootScope的变化而改变.我需要一个想法如何更好地解决它或如何再次触发过滤器来改变我的文本.
这是我如何使用过滤器
<p>greet: {{'GREETING' | ci18n}}</p>
Run Code Online (Sandbox Code Playgroud) javascript angularjs angularjs-scope angularjs-filter angularjs-ng-click
$scope.add=function()
{
//How to retrieve the value of textbox
}
<input type='text'><button ng-click='add()'></button>
Run Code Online (Sandbox Code Playgroud)
当我单击按钮时,如何检索控制器中的文本框值并动态地将该值添加到表中?
javascript angularjs angularjs-controller angularjs-ng-click angular-ngmodel
我有类似于以下代码的代码来触发clickAngular应用程序中的事件.为什么事件不会触发?
var app = angular.module("myApp", [])
app.directive('myTop',function($compile) {
return {
restrict: 'E',
template: '<div></div>',
replace: true,
link: function (scope, element) {
var childElement = '<button ng-click="clickFunc()">CLICK</button>';
element.append(childElement);
$compile(childElement)(scope);
scope.clickFunc = function () {
alert('Hello, world!');
};
}
}
})
Run Code Online (Sandbox Code Playgroud) angularjs ×10
javascript ×8
asp.net-mvc ×1
data-binding ×1
function ×1
html ×1
ng-repeat ×1
parameters ×1