什么是ng-click中的setSize
What is setSize in ng-click?
我正在尝试研究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。有了这个代码,我提供你应该能够管理和让它现在工作:-)祝你好运!
- 无法从 jQuery RSS Feed 中的 localStorage 动态替换类
- 可以't让我的if语句处理js中的html表单输入
- 引用对象中的通用值
- 使用JS如何动态更改显示的html文件中的文本背景颜色
- 用程序搜索JQuery数据表中的文本
- 无法导出函数expressjs/requestjs中的变量
- 函数参数中的数据与指定变量之间的任何性能差异
- 不能从angular2中的子组件指定父组件中的数组
- Dojo不解析自定义小部件的模板html中的小部件声明性
- 如何在angularJS中编辑时,如果DB中的值为true,则设置复选框,如果值为false,则取消选中复选框
- 正在验证8个真/假复选框或复选框中的2个
- Javascript-如何读取json文件中的列并将其保存在Javascript数组中
- 如何更改bigquery API中的计费层选项
- 将输入字段中的文本提交到我的数据库,同时将其添加到我的列表中
- 将jsp文件下拉列表中的选定项分配给一个java变量(比如String selection)
- 使用Dnamics CRM 2011中的JavaScript读取子网格的所有记录,而不考虑活动页面
- 拨打'父亲'函数形式a'儿童'ReactJS中的组件
- 我如何找到一个句子中的所有空格并替换忽略它们
- zurb基础中的固定宽度立柱3
- 什么是ng-click中的setSize