我按照这个例子http://jsfiddle.net/simpulton/XqDxG/,也可以在这里找到http://youtu.be/1OALSkJGsRw
var myModule = angular.module('myModule', []);
myModule.factory('mySharedService', function($rootScope) {
var sharedService = {};
sharedService.message = '';
sharedService.prepForBroadcast = function(msg) {
this.message = msg;
this.broadcastItem();
};
sharedService.broadcastItem = function() {
$rootScope.$broadcast('handleBroadcast');
};
return sharedService;
});
Run Code Online (Sandbox Code Playgroud)
总是得到这个消息后
错误:未知提供者:sharedServiceProvider < - sharedService
我只是复制了jsfiddle的代码.我很惊讶 同样的错误.疯狂,导致jsfiddle代码工作完美.
这段代码可以弃用吗?
我Autofac.ContainerBuilder在我的ASP.Net MVC 4应用程序中使用,这使得默认控制器出现问题以生成多个实例.
我试着这样处理它
builder.RegisterType<AccountController>().As<IController>().PreserveExistingDefaults();
Run Code Online (Sandbox Code Playgroud)
但没用
码
protected void Application_Start()
{
var dataPath = "~/App_Data/" + ConfigurationManager.AppSettings["Blog_Site"];
var builder = new ContainerBuilder();
builder.RegisterType<ExtensibleActionInvoker>().As<IActionInvoker>().InstancePerHttpRequest();
builder.RegisterControllers(Assembly.GetExecutingAssembly()).InjectActionInvoker().InstancePerHttpRequest();
builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
builder.RegisterType<JsonRepository>().As<IRepository>().InstancePerLifetimeScope().WithParameter("dataPath", HttpContext.Current.Server.MapPath(dataPath));
builder.RegisterType<ConfigService>().As<IConfigService>().InstancePerLifetimeScope();
builder.RegisterType<EntryService>().As<IEntryService>().InstancePerLifetimeScope();
builder.RegisterType<UserService>().As<IUserService>().InstancePerLifetimeScope();
builder.RegisterType<MessageService>().As<IMessageService>().InstancePerLifetimeScope();
builder.RegisterType<CloudService>().As<ICloudService>().InstancePerLifetimeScope();
builder.RegisterType<Services>().As<IServices>().InstancePerLifetimeScope();
_containerProvider = new ContainerProvider(builder.Build());
ControllerBuilder.Current.SetControllerFactory(new AutofacControllerFactory(ContainerProvider));
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(System.Web.Optimization.BundleTable.Bundles);
AuthConfig.RegisterAuth();
HtmlHelper.ClientValidationEnabled = true;
HtmlHelper.UnobtrusiveJavaScriptEnabled = true;
// Quartz.NET scheduler
ISchedulerFactory factory = new StdSchedulerFactory();
var scheduler = factory.GetScheduler();
scheduler.JobFactory = new AutofacJobFactory(ContainerProvider);
scheduler.Start();
}
Run Code Online (Sandbox Code Playgroud)
当我尝试访问默认控制器帐户/管理我得到以下错误.
这我是如何看待的
@Html.Action("RemoveExternalLogins")
<h3>Add an external login</h3> …Run Code Online (Sandbox Code Playgroud) 我最新的CakePHP应用程序出了问题.
我为类别制作了模型和控制器.
型号:Categorie.php
class Categorie extends AppModel{
public $name = 'Categorie';
}
Run Code Online (Sandbox Code Playgroud)
控制器:CategoriesController.php
class CategoriesController extends AppController {
public function index(){
$this->set('list', $this->Categorie->find('all'));
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我访问该页面时,我收到错误:
Fatal error: Call to a member function find() on a non-object
Run Code Online (Sandbox Code Playgroud)
当我添加
$this->loadModel('Categorie');
Run Code Online (Sandbox Code Playgroud)
到我的控制器中的索引函数它将工作.
所以我猜模型和控制器之间的连接不起作用,但我不确定,我不知道如何解决这个问题.
请帮帮我.
日Thnx
我正在关注此视频教程并学习如何从头开始创建身份验证:
http://www.youtube.com/watch?v=O5RDisWr_7Q
这是我的用户迁移文件:
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :email
t.string :password_hash
t.string :password_salt
t.timestamps
end
end
end
Run Code Online (Sandbox Code Playgroud)
而我的控制器:
class UsersController < ApplicationController
def new
@user = User.new
end
def create
@user = User.new(params[:users])
if @user.save
redirect_to root_url, :notice => "Signed up!"
else
render "new"
end
end
end
Run Code Online (Sandbox Code Playgroud)
最后我的模型:
class User < ActiveRecord::Base
attr_accessible :email, :password_hash, :password_salt
before_save :encrypt_password
validates_confirmation_of :password
validates :password, presence: true
validates :email, presence: true
def encrypt_password
if password.present?
self.password_salt = …Run Code Online (Sandbox Code Playgroud) 我是一名java开发人员,并且使用传统的Grails应用程序.我有一个控制器类和许多java类.控制器具有启动/停止java类中描述的任务的方法.我正在使用ScheduledExecutorService它.
问题是每次重新部署应用程序时,我都必须调用http://application/controller/start它来初始化调度程序.我希望controller.start()在启动te应用程序时调用此方法一次.我怎样才能实现这一目标,还是有更好的方法来做到这一点?
我不需要将整个网站放在SSL(https://)下, 而只需要支付控制器.
是否可以[RequireHttps]仅用于该控制器,还是应该应用于每个控制器?
谢谢!
在为Controller编写单元测试的过程中,我需要设置或初始化 -
ControllerContext.HttpContext.Request.QueryString
Run Code Online (Sandbox Code Playgroud)
设置它的最简单方法是什么,以便我可以实际通过ControllerContext.HttpContext.Request.QueryString- 并对控制器进行测试?
我正在使用link_to来启动一个需要两个参数的控制器方法,以便执行我需要它执行的步骤.我似乎无法正确使用语法,我想知道是否因为您在使用此特定语法时无法传递多个参数.这是我到目前为止:
<%= link_to 'Select',
{controller: 'groups',
action: 'associate_subgroup_with_org',
organization_id: organization.id,
subgroup_id: @activity.group.id},
class: 'button' %>
def associate_subgroup_with_org
@organization = Group.find(params[:organization_id])
@subgroup = Group.find(params[:subgroup_id])
@subgroup.parent_group_id = @organization.id
respond_to do |format|
format.js
end
end
Run Code Online (Sandbox Code Playgroud)
链接不起作用,我从不输入我的控制器操作associate_subgroup_with_org.有人可以帮助我正确理解语法吗?
我是laravel4的新手,并且设置了嵌套控制器.我在控制器目录中有一个"Admin"子目录,其中admin控制器驻留在该目录中.我的管理员控制器在我的控制器目录中扩展了一个"AdminController".我已经设置了这样的管理控制器
<?php
namespace Admin;
use AdminController;
class HomeController extends AdminController {
public $layout = 'admin.layouts.master';
public function index() {
$this->layout->content = View::make('admin.dashboard');
}
}
Run Code Online (Sandbox Code Playgroud)
在我的routes.php文件中
/** Admin Routes **/
Route::group(array('domain' => 'admin.vigap.local'), function()
{
//Dashboard
Route::get('/', 'Admin\HomeController@index');
});
Run Code Online (Sandbox Code Playgroud)
但是当我导航到http://admin.xyz.local时,我收到一条错误消息" Class'Admin\View'not found".我究竟做错了什么?
我正在尝试根据控制器中的Javascript Date对象在视图中显示当前时间.我的控制器看起来像这样:
myApp.controller('DateCtrl', function($scope) {
var date = new Date();
$scope.minutes = date.getMinutes();
$scope.hours = date.getHours();
$scope.seconds = date.getSeconds();
var updateTime = function() {
var date2 = new Date();
$scope.minutes = date2.getMinutes();
$scope.hours = date2.getHours();
$scope.seconds = date2.getSeconds();
}
$scope.clickUpdate = function() {
setInterval(updateTime, 1000);
}
});
Run Code Online (Sandbox Code Playgroud)
在我看来,我只是:
<div ng-controller="DateCtrl">
<div>This is the hour: {{ hours }}</div>
<div>This is the minute: {{ minutes }}</div>
<div>This is the second: {{ seconds }}</div>
<button ng-click="clickUpdate()">Click Update Here!</button>
</div>
Run Code Online (Sandbox Code Playgroud)
由于某种原因,该setInterval()方法只能工作一次,我无法让它updateTime() …
javascript model-view-controller controller setinterval angularjs
controller ×10
angularjs ×2
model ×2
.net ×1
asp.net-mvc ×1
autofac ×1
c# ×1
cakephp ×1
connection ×1
forms ×1
grails ×1
https ×1
javascript ×1
laravel ×1
laravel-4 ×1
link-to ×1
ruby ×1
setinterval ×1
ssl ×1
unit-testing ×1