javascript - how do you set cookies in angular? -


i have angularjs function translate text. entire controller looks this:

ntsvapp.controller('ntctrl', function($translate){    var ctrl = this;      ctrl.language = 'en';     ctrl.languages = ['en', 'de'];     ctrl.updatelanguage = function(){         $translate.use(ctrl.language);      }; }); 

if put $cookies updatelanguage function able set cookies, angular doesn't recognize $translate.use method. if place $cookies inside controller function, doesn't recognize $cookies.put method. if put both cookies , translate in either controller or updatelanguage nothing works. how make writing cookies works withing updatelanguage function?

this should work dependency injection,

ntsvapp.controller('ntctrl', ['$translate', '$cookies', function($translate, $cookies){    var ctrl = this;      ctrl.language = 'en';     ctrl.languages = ['en', 'de'];     ctrl.updatelanguage = function(){         $translate.use(ctrl.language);      }; }]); 

you can use them anywhere in controller function now.


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

unity3d - Fatal error- Monodevelop-Unity failed to start -