角JS点击事件 [英] Angular js click event

查看:134
本文介绍了角JS点击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Angularjs。我想通过单击(HomeController中)的链接导航到另一个控制器(detailscontroller)和detail.html页面。不过,虽然导航到detailscontroller我应该通过从HomeController的参数值。下面是我的截图

I am using Angularjs. I want to navigate to other controller (detailscontroller) and the detail.html page by clicking the link from (Homecontroller). But while navigate to the detailscontroller i should pass the parameter value from Homecontroller. Below is my screenshot

点击删除就应该导航到detailscontroller控制器,并触发下方的功能

By clicking delete it should navigate to the detailscontroller controller and trigger the below function

detailsController

myApp.controller("detailsController", function ($scope, $http,GENERAL_CONFIG,$filter) {

    $scope.getdetailsbyspider = function(spider){
        console.log(spider)

    }


});

其中的蜘蛛应该从HomeController中(点击值)

Where as the spider should be from the Homecontroller ( the click value)

我怎样才能做到这一点?谁能帮我?

How can i do this ? Can anyone help me ?

更新:我的路由器

.when("/details", { templateUrl: 'Details.html', controller: 'detailsController' }) 

的Home.html

<tbody>
               <tr ng-repeat="row in finished">
                   <td> {{row.project}} </td>
                <td> <a href="#details" ng-click="getdetailsbyspider(row)"> {{row.spider}}</a></td>

要得到上面的表格

更新
当我点击蜘蛛名网页应该是导航与点击蜘蛛名details.html。

Update When i click the Spider name page should be navigate to the details.html with the spider name clicked.

在这个例子中,当我点击删除应导航到details.html并在detailscontroller与蜘蛛名删除执行getdetailsbyspider功能

In this example when i click on the delete it should navigate to the details.html and execute the getdetailsbyspider function in the detailscontroller with the spider name as delete

谢谢,

推荐答案

我会做这样dddd1919说和参数spide添加到URL
在HomeController的:

i will do like dddd1919 says and add the parameter spide to the url in homecontroller :

       myApp.controller("HomeController", function ($scope, $http,GENERAL_CONFIG,$filter) {
         $scope.callGetDetail = function(spider){
            console.log("callGetDetail");
            $location.path("/YourDomaine/#/details/getdetailsbyspider="+spider);
        }
     });

在你想呼叫的看法,home.html的

in the view where you want to make the call, home.html

          <tbody>
           <tr ng-repeat="row in finished">
               <td> {{row.project}} </td>
            <td> <a href="#details" ng-click="callGetDetail(row)"> 
             {{row.spider}}</a>
            </td>

在路由器

    when('/details/:params', {
        templateUrl: 'Details.html',
        controller: 'detailsController'
     }).

在detailsController:

in the detailsController:

     myApp.controller("detailsController", function ($scope, $http, GENERAL_CONFIG, $filter,$routeParams) {
        $scope.getdetailsbyspider = function(spider){
            console.log("getdetailsbyspider "+ spider)
        }

        function myUrlToArray(url) {
           var paramsFormatted = {};
           var paramstmp = decodeURI(url).split("&");
           for (var index = 0; index < paramstmp.length; ++index) {
              var tmp = paramstmp[index].split("=");
              paramsFormatted[ tmp[0] ] = tmp[1];
           }
           return paramsFormatted;
        }
       var params =  myUrlToArray($routeParams.params)
       if(params.getdetailsbyspider != null ){
                  $scope.getdetailsbyspider(params.getdetailsbyspider);
        }
    });

这篇关于角JS点击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆