NG-click事件不是作品的角度JS链接 [英] ng-click event not works for link in angular js
问题描述
喜在我的角度应用程序,我使用routeProvider路由谐音,
并在一个页面,我有一组我使用NG-的href提供链接的链接。我有该链接的NG-click事件。但是当我点击页面去routeProvider的,否则部分的链接,并加载页面我已经定义了那里。
见code
HTML
<李NG重复=项supplyItem>
<一类=跨度NG点击=showDetails()NG-HREF =#{{item.header}}>
{{item.header}}
&所述; / A>
< /李>
App.js
VAR对myApp = angular.module(对myApp,[
ngRoute',
AppController的
]);myApp.config(['$ routeProvider',函数($ routeProvider){
$ routeProvider。
当('/家',{
templateUrl:'谐音/ home_page.aspx',
控制器:'HomePageController',
})。
当('/耗材',{
templateUrl:'谐音/ supplies.aspx',
控制器:'SupplyController',
})。
除此以外({
redirectTo:'/家
});
}]);
controller.js
appController.controller('SupplyController',['$范围',函数($范围){
$ scope.firstITem =丙烯酸;
$ scope.showDetails =功能(){
警报(点击); }
$ scope.supplyItem = [
{
头:丙烯酸酯
亚克力:[
定制托盘材料,
换衬材料,
换衬材料 - 硬
换衬材料软
修复亚克力
树脂和放大器;图案材料,
临时冠桥材料,
组织润发
]
}
];
}]);
什么是错误?我怎么能解决这个问题。
$ scope.showDetails =功能(){
在此输入code
}
松散的NG-HREF,如果你想链接到click事件之后激活。
<李NG重复=项supplyItem>
<一类=跨度NG点击=showDetails(项目)>
{{item.header}}
&所述; / A>
< /李>$ scope.showDetails =功能(项目){ 警报();
window.location.href =#+ item.header;
}
Hi in my angular application, I am using routeProvider for routing partials, and in one page i have a set of links i am using ng-href for providing link. and I have a ng-click event for the link. but when I click on the link the page goes to the otherWise section of routeProvider and loads the page I have defined there.
see the code
HTML
<li ng-repeat="item in supplyItem">
<a class="span" ng-click="showDetails()" ng-href="#{{item.header}}">
{{item.header}}
</a>
</li>
App.js
var myApp = angular.module("myApp",[
'ngRoute',
'appController'
]);
myApp.config(['$routeProvider',function($routeProvider){
$routeProvider.
when('/home',{
templateUrl : 'partials/home_page.aspx',
controller:'HomePageController',
}).
when('/supplies',{
templateUrl : 'partials/supplies.aspx',
controller:'SupplyController',
}).
otherwise({
redirectTo: '/home'
});
}]);
controller.js
appController.controller('SupplyController', ['$scope', function ($scope) {
$scope.firstITem = "Acrylics";
$scope.showDetails = function() {
alert("clicked");
}
$scope.supplyItem = [
{
"header": "Acrylics",
"Acrylics": [
"Custom Tray Material",
"Reline Materials",
"Reline Materials-Hard",
"Reline Materials-Soft",
"Repair Acrylics",
"Resin & Pattern Materials",
"Temporary Crown and Bridge Material",
"Tissue Conditioner",
]
}
];
} ]);
what is the error ? how can I solve this
$scope.showDetails = function() {
enter code here
}
loose the ng-href, if you want the link to activate after the click event.
<li ng-repeat="item in supplyItem">
<a class="span" ng-click="showDetails(item)">
{{item.header}}
</a>
</li>
$scope.showDetails = function(item) {
alert();
window.location.href = "#' + item.header;
}
这篇关于NG-click事件不是作品的角度JS链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!