简体   繁体   English

角js单击事件

[英]Angular js click event

I am using Angularjs. 我正在使用Angularjs。 I want to navigate to other controller (detailscontroller) and the detail.html page by clicking the link from (Homecontroller). 我想通过单击(Homecontroller)中的链接导航到其他控制器(detailscontroller)和detail.html页面。 But while navigate to the detailscontroller i should pass the parameter value from Homecontroller. 但是,当导航到detailscontroller时,我应该从Homecontroller传递参数值。 Below is my screenshot 下面是我的截图

在此处输入图片说明

By clicking delete it should navigate to the detailscontroller controller and trigger the below function 通过单击删除,它应该导航到detailscontroller控制器并触发以下功能

detailsController detailsController

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

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

    }


});

Where as the spider should be from the Homecontroller ( the click value) spider应该来自Homecontroller的位置(点击值)

How can i do this ? 我怎样才能做到这一点 ? Can anyone help me ? 谁能帮我 ?

UPDATE: My router 更新:我的路由器

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

Home.html 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>

to get the above table 得到上表

Update When i click the Spider name page should be navigate to the details.html with the spider name clicked. 更新当我单击“蜘蛛名”页面时,应单击“蜘蛛名”,导航到details.html。

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 在此示例中,当我单击删除时,它应导航至details.html并在蜘蛛网名称为delete的detailscontroller中执行getdetailsbyspider函数

Thanks, 谢谢,

i will do like dddd1919 says and add the parameter spide to the url in homecontroller : 我会像dddd1919所说的那样做,并将参数spide添加到homecontroller中的url中:

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

in the view where you want to make the call, home.html 在您要拨打电话的视图中,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>

in the router 在路由器中

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

in the detailsController: 在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);
        }
    });

Based on your comment 根据您的评论

the redirection is working fine. 重定向工作正常。 But the getdetailsbyspider is not able to access. 但是getdetailsbyspider无法访问。 Getting problem in the controller level i hope 我希望控制器级别出现问题

the problem will be that the controller function 问题将在于控制器功能

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

is not part of the controller you are currently in when you trigger it. 触发时它不是您当前所在的控制器的一部分。 That means you call the function by clicking on a link in your home.html but the detailsController is not assigned to that view. 这意味着您可以通过单击home.html的链接来调用该函数,但是detailsController没有分配给该视图。

To prove that just copy the function into your HomeController (or whatever its name is) and you will see the logging will work. 为了证明只需将函数复制到HomeController (或无论其名称是什么),您就会看到日志记录将起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM