Using AngularJS Controllers created with angular.module().controller()
Date : March 29 2020, 07:55 AM
I hope this helps . Try using a string identifier. routeProvider.when('/', {templateUrl: 'partials/home.html', controller: 'home'});
|
How can I test angularjs controllers that have been created with module().controller?
Date : March 29 2020, 07:55 AM
Does that help You test them the same exact way. Make sure you're loading the module with the controller in your tests via the module function in the ngMock module. Something like this: beforeEach(module('testAngularApp'));
|
How to use created module in controller
Date : March 29 2020, 07:55 AM
will help you At first may I suggest you to use "foobar" instead of "test". "test" looks really like, test. Back to question, there are two ways to use it in controller, given you have already loaded the module correctly as per comments. class ApplicationController < ActionController::Base
include ModuleFoo
def index
bar # Use ModuleFoo's method directly
#...
end
end
# ModuleFoo
module ModuleFoo
def bar
end
end
if defined? ActionController::Base
ActionController::Base.class_eval do
include ModuleFoo
end
end
# Controller
class SomethingController < ApplicationController
def some_method
bar # use this directly
end
end
|
How to test controller created via module.config in angularjs
Date : March 29 2020, 07:55 AM
hop of those help? As mentioned in comments by @PaoloMoretti, you shouldn't define your controller in global scope (unless prototyping). Instead definie the controller as part of the module: var mainModule = angular.module('module1');
mainModule.controller('home', function($scope) {
$scope.test = "hello";
});
beforeEach(module('module1'));
|
Can you call a method from a Controller if the View was created from a different Controller?
Date : March 29 2020, 07:55 AM
|