angularjs-controller

Controlling multiple views in one controller in AngularJS

喜夏-厌秋 提交于 2019-12-10 19:08:50
问题 Following the MVC pattern, one controller should be able to handle multiple views in AngularJS. E.g. I have one view for showing all users and one for creating a new user. My $routeProvider (excerpt) looks like this: app.config(['$routeProvider', function($routeProvider) { $routeProvider. when('/showusers', { templateUrl: 'partials/showusers.html', controller: 'userController' }). when('/createuser', { templateUrl: 'partials/showusers.html', controller: 'userController' }) }]); Both views

Change a value inside ng-repeat cycle with ng-click

 ̄綄美尐妖づ 提交于 2019-12-10 16:18:58
问题 I want to change a value of an item inside an ng-repeat cycle using a function. This for example won't work. HTML <ul class="unstyled"> <li ng-repeat="todo in todoList.todos"> <span>{{todo.name}}</span> <button ng-click="example(todo)">Change me</button> </li> </ul> JS $scope.example = function(v) { v.name = 'i am different now'; }; Full example http://plnkr.co/edit/kobMJCsj4bvk02sveGdG 回答1: When using controllerAs pattern, you should be using controller alias while accessing any variable

Controller being called twice in Ionic (AngularJS)

烈酒焚心 提交于 2019-12-10 15:15:16
问题 In my angular project the user accepts a EULA then get automatically redirected to their dashboard, however, on this redirect the DashboardController seems to be being called twice, the DashboardController is being called on the route itself, I have checked to see if I have accidently called it again in the template but I havn't. Below is my route & controller. It doesn't appear to matter if I access the URL directly or via the redirect on the EULA controller, I get the same result. The

Pass Data $http.post From AngularJS and ASP.net MVC gets null

寵の児 提交于 2019-12-10 04:10:17
问题 i'm trying to pass data from AngularJS to ASP.net MVC and is always getting null. Here's my code (only posting the essential, button, controller and c#: HTML: <a class="btn btn-grey btn-lg btn-block" ng-click="AddCar()">Save</a> Controller $scope.AddCar = function () { $http.post("Cars/AddCar", JSON.stringify($scope.new.JsonCar)).success(function (data) { Alert(ok) }) c# public string AddCar(string JsonCar) { try .... } In JSON.stringify($scope.new.JsonCar) i'm getting this: "{"Name":"FIAT

Sharing data between AngularJS controllers? [duplicate]

随声附和 提交于 2019-12-09 09:43:22
问题 This question already has answers here : Can one AngularJS controller call another? (13 answers) Closed 6 years ago . How do I store the items I've selected in a checkbox with other controllers? My attempt (see the plnkr for views): script.js (controllers) var myApp = angular.module('myApp', []); myApp.factory('CooSelection', function () { return {selectedCoo: []} }) function CooListCtrl($scope, CooSelection) { $scope.coos = {"Coos": ["spark", "nark", "hark", "quark"]}; $scope.coo_list

Angular-ui bootstrap modal without creating new controller

十年热恋 提交于 2019-12-09 07:53:48
问题 plunk: http://plnkr.co/edit/85Wl5W If I use the $modalInstance on the same controller(modalController.js), without being in a modal, angular gets frozen. I just want to simplify my life using angularjs with the angular-ui bootstrap modal service. I want to use the same controller on a separate file, but on a modal as well. That is, I want them to do the same task. Is there any proper way to do it? E.g. modal.html, modalController.js. I want to show these on a modal window, but on my

Nested directives - cannot pass args to controller method from child directive in Angularjs

喜欢而已 提交于 2019-12-09 06:04:35
问题 I'm having some trouble with nested directives in angularjs. I want to call a controller method from a directive within another directive and am trying to pass arguments to it, however they are undefined. I'm attempting to call remove() with three arguments from selected.html below. It was working before I introduced a parent directive (televisionFilter.js) Can anyone suggest what to do to pass these to the controller? Thanks! Code: controller.js $scope.remove = function(selectorToRemove,

Where should I place code to be used across components/controllers for an AngularJS app?

旧巷老猫 提交于 2019-12-09 03:43:37
问题 Should it be associated with the app module? Should it be a component or just a controller? Basically what I am trying to achieve is a common layout across all pages within which I can place or remove other components. Here is what my app's structure roughly looks like: -/bower_components -/core -/login --login.component.js --login.module.js --login.template.html -/register --register.component.js --register.module.js --register.template.html -app.css -app.module.js -index.html 回答1: This

Service functions outside Angularjs scope

☆樱花仙子☆ 提交于 2019-12-08 17:36:42
问题 I have created a service in angularJS that uses btford.socket-io module to interact with the server. Since in the service I have implemented some API that I use inside angular at the moment, but for later extension of the application I also need to give access to these API outside angular scope. So that in future one could just call the function without having the need to create controller and other stuff. At the moment I did this for a controller var myController = angular.element($('body'))

Angular controller can't get data from service

非 Y 不嫁゛ 提交于 2019-12-08 12:50:45
问题 Background: I'm learning AngularJS, I've written sample code to create a service for a module, and pass the data from service into one of the module's controller, all works fine. But yesterday when I tried to pass the following service's data into a controller, it just show the data is undefined, and I don't know why. var notif = angular.module('testnotif',[]); notif.service('sharedUsers', ['$http', function($http){ var url = current_dir+'/testNotif/getAllUsersjson'; var allUsers = []; var