什么是ng-click中的setSize

What is setSize in ng-click?

本文关键字:setSize 中的 ng-click 什么      更新时间:2023-09-26

我正在尝试研究API(我也查找了它的含义,是不是在一个页面上的一个小区域,被编程为在它的编码中起作用(例如,你在其中设置闹钟并在特定时间响,正确吗?))在https://www.barkbox.com/subscribe/size。

我知道它在Angular JS中,我甚至研究了Angular UI路由器。我知道,你可以编程的链接去另一个页面,而无需重新加载页面,这是类似于我正在寻找。例如,ui-sref="home"将从home.html调用代码。此外,在ngRoute方法中,您使用a href="#about"来调用about.html中的代码。但在我提供的这个链接的Barkbox应用程序中,我没有看到两者。

我认为会导致这个barkbox应用程序工作的唯一线索是ng-click="setSize('squee')"。我想它的作用是设置框的大小并将整个框链接到另一个页面并使用以下代码或类似的代码:

// app.js
var routerApp = angular.module('dogApp', ['ui.router']);
routerApp.config(function($stateProvider, $urlRouterProvider) {
    $urlRouterProvider.otherwise('/home');
    $stateProvider
        // HOME STATES AND NESTED VIEWS ========================================
        .state('home', {
            url: '/home',
            templateUrl: 'partial-home.html'
        })
        // ABOUT PAGE AND MULTIPLE NAMED VIEWS =================================
        .state('about', {
            // we'll get to this in a bit       
        });
});

我真的从学习https://scotch.io/tutorials/angular-routing-using-ui-router和https://scotch.io/tutorials/single-page-apps-with-angularjs-routing-and-templating中学到了很多。但我还没有在https://github.com/angular-ui/ui-router上学习更多。

仍然,我试图理解setSize函数以及ng-click,因为它们如何链接到另一个页面。我试着查找它,但找不到相关信息,也找不到它与ng-click或类似....的连接任何帮助或建议都是感激的。

--------------- 更新 ----------------------好了,我编好代码了。你可以在http://hamzakhan.name/dev/eric/options/dogsubscription.html#/dogs

看到它

html代码是

<div class="optionwrapper size">
                <div class="option" ng-click="setSize('one')">
                    <div class="numberimage1"></div>
                    <div class="numbercontent">
                        <div class="numbertitle">One</div>
                    </div>
                    <div class="icon-chevron-right"><i class="fa fa-angle-right fa-3x"></i></div>
                </div>
            </div>
            <div class="optionwrapper size">
                <div class="option" ng-click="setSize('two')">
                    <div class="numberimage2"></div>
                    <div class="numbercontent">
                        <div class="numbertitle">Two</div>
                    </div>
                    <div class="icon-chevron-right"><i class="fa fa-angle-right fa-3x"></i></div>
                </div>
            </div>

和javascript代码是

angular.module('dogApp', ['ui.router'])
// configuring our routes 
// =============================================================================
.config(function($stateProvider, $urlRouterProvider) {
     $stateProvider
        // route to show our basic form (/form)
        .state('dogs', {
            url: '/dogs',
            templateUrl: 'dogs.html',
            controller: 'dogController'
        })
        // nested states 
        // each of these sections will have their own view

    // catch all route
    // send users to the form page 
    $urlRouterProvider.otherwise('/dogs');
})
// our controller for the form
// =============================================================================
.controller('dogController', function($scope) {
    // we will store all of our form data in this object
    $scope.dogData = {};
    // url will be nested (/dogs-oneage)
        $scope.setSize = function(one) {
             //url: '/oneage',
            templateUrl: 'dogs-oneage.html'
        }
        // url will be nested (/dogs-twoage)
        $scope.setSize = function(two) {
             //url: '/twoage',
            templateUrl: 'dogs-twoage.html'
        }
        // url will be nested (/dogs-threeage)
        $scope.setSize = function(three) {
             //url: '/threeage',
            templateUrl: 'dogs-threeage.html'
        }
        // url will be nested (/dogs-fourage)
        $scope.setSize = function(four) {
             //url: '/fourage',
            templateUrl: 'dogs-fourage.html'
        }
        // url will be nested (/dogs-fiveage)
        $scope.setSize = function(five) {
             //url: '/fiveage',
            templateUrl: 'dogs-fiveage.html'
        }
    // function to process the form
    $scope.processForm = function() {
        alert('Congratulations! You have finished the first part! Please complete the second part to finish registering.');
    };
});

但无论如何,我无法让盒子链接到另一个页面....(

这是控制器中函数的名称。

基本上ng-click是:'当你点击这里,这个函数将被调用'。因此,当您单击<div><a>时,函数setSize()将被调用。'squee'是传递给函数的参数。该函数所做的是在为页面的特定页面/部分实例化的控制器中编写的。您应该查找类似于以下代码段:$scope.setSize = function(param) {}

更新后的代码:

你可以在控制器中添加$location。一个示例如下:

routerApp.config(['$routeProvider', function($routeProvider) {
    $routeProvider
        .when('/one', {
            templateUrl: '<*the complete link to your html file*>'
        })
         .when('/two', {
            templateUrl: '<*the complete link to your html file*>'
        })
        .otherwise({
             redirectTo: '/home',
            templateUrl: '<*the complete link to your html file*>'
        });
 }])
.controller('dogController',['$scope', '$location', function($scope, $location) {
    $scope.goTo = function(url) {
        $location.path(url);
    }
}
然后你的HTML:
<div class="optionwrapper size">
            <div class="option" ng-click="goTo('/one')">
                <div class="numberimage1"></div>
                <div class="numbercontent">
                    <div class="numbertitle">One</div>
                </div>
                <div class="icon-chevron-right"><i class="fa fa-angle-right fa-3x"></i></div>
            </div>
        </div>
        <div class="optionwrapper size">
            <div class="option" ng-click="goTo('/two')">
                <div class="numberimage2"></div>
                <div class="numbercontent">
                    <div class="numbertitle">Two</div>
                </div>
                <div class="icon-chevron-right"><i class="fa fa-angle-right fa-3x"></i></div>
            </div>
        </div>

这里发生了什么:你告诉你的应用程序,当url匹配".com/one",它将打开模板1。你的div现在有ng-click=goTo('/one'),然后与$location.path它将直接到url ".com/one"。

你想在教程中使用的setSize()方法是一个你可以随意更改的名称。在教程中,它可能被称为setSize,因为它调整了某些东西的大小。这里我将其重命名为goTo(),因为您想要访问某个url。有了这个代码,我提供你应该能够管理和让它现在工作:-)祝你好运!