Loading controller on demand using AngularJS and RequireJS -


I am using an angle UI router and am trying to change / download routing changes. I used Resolution and Category, returns the JS file content as data.data string. I am not sure to make the controller available for angular please

my module Js contains the routing code

  state ("privacy", {url: "/ privacy", controller provider: function ($ stateParams) {return "privacy controller";}, resolution: { Category: ['$ http', '$ state parasomes', function ($ http, $ state page) {$ $ http.get ("js / privacy.js") back. (Function data) {return data.data; }}}}}, templateUrl: localPath + "templates / privacy.html"})   

"Administrator exists below js / privacy.js"

socialinviter.controller ("privacy controller", function ($ radius) {$ scope.me = "Hello world";});

I also tried with the requirement of JS, but I'm getting the error ""

  Solution: {deps: function ($ q, $ RootScope) {var deferred = $ q.defer (), Dependency = "js / privacy"]; Expected (Dependence, Work () {$ rootScope. $ Apply (function () {deferred.resolve ();}); deferred.resolve ()} Return deferred.promise; }}    

I have solved this issue and I thought the solution was for others

Step 1: Include the parameter $ controller provider in your config

 > mytestapp.config (function ($ stateProvider, $ controller provider)  < / pre> 

Step 2: Tell the angular to register the controller downloaded as the controller,

 > mytestapp.config (function ($ stateProvider, $ controllerProvider) {mytestapp ._controller = mytestapp} Controller mytestapp.controller = function (name, constructor) {$ controllerProvider.register (name, constructor); return (this);} ......   

step 3: add down Resolve the given method

  state ("privacy", {url: "/ privacy", controller: "privacy controller", solve: {deps: function ($ q, $ rootScope ) {var deferred = $ Q.defer (); (["js / privacy"], function (tt) {$ rootScope. $ apply (function () {deferred.resolve ();}); Deferr ed.resolve ()}); Refund refund. }}, TemplateUrl: "templates / privacy.html"})    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -