对于AngularJS应用程序中的任何给定路线或状态,我希望根据用户设备使用移动专用模板或桌面专用模板的选项。我还希望用户能够选择哪个版本(台式机或移动版),无论他们使用什么设备。
具体来说,我想要一个单独的模板,因为在许多情况下,单独的模板比使用响应式设计要简单得多。
有没有简单的方法可以做到这一点?
这是我想做的事情,但我不知道如何使用angular-ui-router使templateUrl函数可访问“ isMobile”变量。任何帮助将不胜感激。
angular
.module('app.items', [])
.config(config);
function config($stateProvider) {
//$window service not available in config block, so how can I set this variable?
var isMobile = $window.sessionStorage.getItem('isMobile');
$stateProvider
.state('itemsList', {
url: '/items',
templateUrl: function($stateParams) {
if (isMobile) { //How do I get this information (variable) in here?
return 'app/items/list.mobile.html';
}
else {
return 'app/items/list.desktop.html'
}
},
controller: 'ItemsListController'
});
}
Run Code Online (Sandbox Code Playgroud) 我需要帮助将 PouchDB 与 Couchbase 同步网关同步。
我不断收到指向 CORS 问题的以下错误,但我已经根据他们的文档为 CORS 配置了 Couchbase 同步网关 (CSG)。
XMLHttpRequest cannot load http://localhost:4985/test-database/.
No 'Access-Control-Allow-Origin'header is present on the requested
resource. Origin 'http://localhost:3000' is therefore not
allowed access.
Run Code Online (Sandbox Code Playgroud)
我已经根据 CSG 文档尝试了以下配置文件:
{
"log": ["HTTP+"],
"CORS": {
"origin":["http://localhost:3000"],
"loginOrigin":["http://localhost:3000"],
"headers":["Content-Type"],
"maxAge": 1728000
},
"databases": {
"test-database": {
"server": "walrus:",
"users": { "GUEST": {"disabled": false, "admin_channels": ["*"] } }
}
}
}
Run Code Online (Sandbox Code Playgroud)
我也尝试过 Couchbase 博客中的其他配置文件,但它们都不起作用!对此的任何帮助将不胜感激!
如何在下拉框中设置id属性?
这是我的表格中的一部分:
<%= f.fields_for :items do |builder| %>
<%= builder.label :description %><br />
<%= builder.text_field :description %><br />
<%= builder.label :material %><br />
<%= builder.select :material, @letters.map { |l| [l.material, l.material] }, :id => "material_field" %><br />
<%= builder.label :height %><br />
<%= builder.select :height, @letters.map { |l| [l.height, l.height] }, :id => "height_field" %><br />
<%= builder.label :thickness %><br />
<%= builder.select :thickness, @letters.map { |l| [l.thickness, l.thickness] }, :id => "thickness_field" %><br />
<%= builder.label :quantity %><br /> …Run Code Online (Sandbox Code Playgroud) 如何为为手机设计的AngularJS视图和从Rails API为桌面设计的AngularJS视图包含一组不同的资源(CSS和JavaScript)?默认模板(application.html.erb或index.html)通常只会使用初始请求加载一次,因为它是一个AngularJS应用程序,因此我认为Rails应用程序的常用桌面与移动解决方案不起作用.
具体来说,我正在尝试将使用AngularJS,Bootstrap和jQuery的桌面应用程序与使用AngularJS和Ionic的移动应用程序相结合.除视图外,这两个应用程序大多数都有共享代码.观点将大不相同,因此响应方法是不够的.我根本找不到这方面的指导.任何帮助将不胜感激.
升级到OSX Yosemite后,我无法再使用我的开发机器(MacBook Pro)IP地址在移动设备上测试我的应用程序.例如,我曾经能够通过访问http://192.168.0.4:3000在手机上查看Rails应用程序,但现在我收到以下错误:
ERR_CONNECTION_REFUSED
Run Code Online (Sandbox Code Playgroud)
使用运行在http://192.168.0.4:9000的grunt服务器测试AngularJS应用程序时出现同样的错误
任何帮助将不胜感激.
创建与特定帐户关联的人员后,如何重定向回"帐户"页面?
account_id通过URL参数传递给CREATE Person操作,如下所示:
http://localhost:3000/people/new?account_id=1
Run Code Online (Sandbox Code Playgroud)
这是代码:
<h2>Account:
<%= Account.find_by_id(params[:account_id]).organizations.
primary.first.name %>
</h2>
<%= form_for @person do |f| %>
<%= f.hidden_field :account_id, :value => params[:account_id] %><br />
<%= f.label :first_name %><br />
<%= f.text_field :first_name %><br />
<%= f.label :last_name %><br />
<%= f.text_field :last_name %><br />
<%= f.label :email1 %><br />
<%= f.text_field :email1 %><br />
<%= f.label :home_phone %><br />
<%= f.text_field :home_phone %><br />
<%= f.submit "Add person" %>
<% end %>
class PeopleController < ApplicationController
def new
@person …Run Code Online (Sandbox Code Playgroud) 如何使用AngularJS切换Bootstrap 3网格系统列宽(col-*)?我正在尝试使用如下所示的ng-class,但它不起作用.任何帮助将不胜感激.
这是我视图中的网格结构:
<div class="row">
<div ng-class="{{columnWidth}}"></div>
<div ng-class="{{columnWidth}}"></div>
<div ng-class="{{columnWidth}}"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
这是我的控制器中的变量:
$scope.columnWidth = "col-md-3"; //Toggle between "col-md-3" and "col-md-4"
Run Code Online (Sandbox Code Playgroud)
无论我设置范围变量是什么,列都只是堆叠,好像我在移动设备上一样.
如何通过Rails 3.2中可选的多个参数进行搜索/过滤?通过下面的设置,我目前收到以下错误.任何帮助是极大的赞赏.
undefined method `paginate' for nil:NilClass
Application Trace | Framework Trace | Full Trace
app/controllers/contacts_controller.rb:50:in `index'
Run Code Online (Sandbox Code Playgroud)
这是我的contacts_controller中的索引操作:
def index
city = params[:city]
state = params[:state]
zip = params[:zip]
@contacts = Contact.search(city,state,zip).paginate(:page => params[:page], :per_page => items_per_page)
end
Run Code Online (Sandbox Code Playgroud)
这是我的Contact模型中的搜索方法:
def self.search(city, state, zip)
joins(:profile => :addresses)
.where("city like ?", "%#{city}%") unless city.blank?
.where("state = ?", state) unless state.blank?
.where("zip like ?", "%#{zip}%") unless zip.blank?
end
Run Code Online (Sandbox Code Playgroud) 我尝试按照官方CouchDB docs docs.couchdb.org上的说明通过Homebrew安装CouchDB 1.6,但我没有成功.首先,我尝试了本机应用程序,但有效,但显然该版本不支持CORS.这是一个令人沮丧的经历,所以任何帮助将不胜感激.
这是我在尝试ping CouchDB时遇到的错误:
curl: (7) Failed to connect to 127.0.0.1 port 5984: Connection refused
Run Code Online (Sandbox Code Playgroud)
我按照安装指南进行操作:http://docs.couchdb.org/en/1.6.1/install/mac.html
这些是我使用的终端命令:
open /Applications/Installers/Xcode\ Tools/XcodeTools.mpkg
--> File not found (this step is listed as optional, so I moved on)
brew update
brew doctor
brew install autoconf
brew install autoconf-archive
brew install automake
brew install libtool
brew install erlang
brew install icu4c
brew install spidermonkey
brew install curl
brew link icu4c
--> Requires --force option which can cause installations to fail …Run Code Online (Sandbox Code Playgroud)