【问题标题】:Angular JS controller doesn't work with routingAngular JS 控制器不适用于路由
【发布时间】:2016-11-25 13:34:37
【问题描述】:

我正在使用 Angular JS 1.3,ngRoute 有问题,在下面的代码中 角度重定向到 "apex/" + pathTemplate + "_product"(页面在 Salesforce 容器中工作)但控制不会返回到控制器 homeController

  .when(pathComm + ':categoryCode/:productCode', {
        templateUrl: function () {
            return "apex/" + pathTemplate + "_product"
        },
        controller: "homeController"
    })

当路径只有一个路径变量时,它可以使用 sn-p 代码:

 .when(pathComm + ':productCode', {
        templateUrl: function () {
            return "apex/" + pathTemplate + "_product"
        },
        controller: "homeController"
    })

【问题讨论】:

  • 路由代码看起来没问题。只需检查您是否将控制器添加到应用程序模块:OrdersController.$inject=['$scope', '$routeParams'];angular.module('yourApp') .controller('yourController', yourController);
  • 控制器刚刚添加到应用模块中。

标签: javascript angularjs salesforce angular-routing angular-controller


【解决方案1】:

在 html 中你必须像这样使用 url 传递参数参数:

<a class="btn btn-primary" ng-href="#/student/{{row._id}}/studentName/{{studentName}}">Edit</a>

之后将控制器与包含参数的 url 绑定。像:

.when('/student/:id/studentName/:surName', {                            
    templateUrl: 'templates/student/addForm.html',
    controller: 'YourController'
});

并且像这样在控制器中捕获参数:

 $http.get('/student/'+$routeParams.id +'/studentName/'+ $routeParams.surName).success(function (response) {
 alert(response);
 $scope.studentList = response;
 $scope.id = response['_id'];});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-07
    • 1970-01-01
    • 2017-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多