0

我有一个控制器,没有模板。

当 url 为 /warenkorb ( http://server.com:3000/shop.html#/warenkorb )时,我只想执行一个 javascript 函数

var warenkorb = angular.module('warenkorb', ['ngResource', 'ngRoute'])

    .config(function($routeProvider, $locationProvider) {
        $routeProvider
            .when('/warenkorb', {
                controller: "WarenkorbCtrl",
                resolve: {
                    // I will cause a 1 second delay
                    cart_visible: function () {
                       showWarenkorb();                            
                       return true;
                    }
                }
            });
    });

var showWarenkorb = function(){
    $('#response').css('display', 'none');
    $('#modal').fadeIn();
}
var hideWarenkorb = function(){
    $('#modal').fadeOut();
}

我该怎么做?在我的示例 showWarenkorb() 中从未调用过。

4

1 回答 1

0

有时 angularjs 只是一个矫枉过正

我使用了我在控制器中调用的。作品。

// simple routing
function getUrlParameter(sParam) {
    var sPageURL = window.location.search.substring(1);
    var sURLVariables = sPageURL.split('&');
    for (var i = 0; i < sURLVariables.length; i++)
    {
        var sParameterName = sURLVariables[i].split('=');
        if (sParameterName[0] == sParam)
        {
            return sParameterName[1];
        }
    }
}
于 2014-10-24T08:57:06.783 回答