标签: controller

AngularJS错误:未知提供者:sharedServiceProvider < - sharedService

我按照这个例子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代码工作完美.

这段代码可以弃用吗?

controller communication angularjs

1
推荐指数
1
解决办法
1万
查看次数

单个控制器实例不能用于处理多个请求 - Autofac

我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)

controller autofac requestfactory asp.net-mvc-4

1
推荐指数
1
解决办法
7425
查看次数

CakePHP:模型和控制器之间的连接失败

我最新的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

connection controller cakephp model

1
推荐指数
1
解决办法
596
查看次数

## User:1123123123>的未定义方法`password'

我正在关注此视频教程并学习如何从头开始创建身份验证:

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)

ruby forms controller model ruby-on-rails-3

1
推荐指数
1
解决办法
1561
查看次数

如何让Grails在启动时执行控制器方法?

我是一名java开发人员,并且使用传统的Grails应用程序.我有一个控制器类和许多java类.控制器具有启动/停止java类中描述的任务的方法.我正在使用ScheduledExecutorService它.

问题是每次重新部署应用程序时,我都必须调用http://application/controller/start它来初始化调度程序.我希望controller.start()在启动te应用程序时调用此方法一次.我怎样才能实现这一目标,还是有更好的方法来做到这一点?

grails controller

1
推荐指数
1
解决办法
2574
查看次数

SSL和ASP .NET MVC

我不需要将整个网站放在SSL(https://)下, 而只需要支付控制器.

是否可以[RequireHttps]仅用于该控制器,还是应该应用于每个控制器?

谢谢!

.net asp.net-mvc ssl https controller

1
推荐指数
1
解决办法
1830
查看次数

ControllerContext.HttpContext单元测试的初始化

在为Controller编写单元测试的过程中,我需要设置或初始化 -

ControllerContext.HttpContext.Request.QueryString
Run Code Online (Sandbox Code Playgroud)

设置它的最简单方法是什么,以便我可以实际通过ControllerContext.HttpContext.Request.QueryString- 并对控制器进行测试?

c# unit-testing controller asp.net-mvc-3

1
推荐指数
1
解决办法
2814
查看次数

如何将多个参数传递给我指定控制器和操作的link_to调用?

我正在使用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.有人可以帮助我正确理解语法吗?

controller ruby-on-rails link-to ruby-on-rails-3

1
推荐指数
1
解决办法
7377
查看次数

Laravel 4中的嵌套控制器

我是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".我究竟做错了什么?

controller laravel laravel-4

1
推荐指数
1
解决办法
3860
查看次数

AngularJS通知视图模型的更改

我正在尝试根据控制器中的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

1
推荐指数
1
解决办法
5839
查看次数