Talking to Angular Directive from Controller
By : algri
Date : March 29 2020, 07:55 AM
it helps some times To call directive methods outside in a controller I would share a directive control object with the controller. Inside the controller you can call methods of this control object and they get executed inside your directive. create a control object inside your directive share this control object with the controller using tw data binding call methods on this control object inside your controller
|
Angular Js newbie - link in a controller view that triggers another controller action
By : user2263994
Date : March 29 2020, 07:55 AM
I hope this helps you . angular newbie here. , This is how it would work - code :
<div ng-controller="mainController">
<button data-ng-click="OnNewButtonClick()">Show News</button>
<button data-ng-click="OnLoginAttemptButtonClick()">Show Login Attempts</button>
</div>
<div ng-controller="newsController">
{{newsControllerData.News}}
</div>
<div ng-controller="loginAttemptsController">
{{loginAttemptsControllerData.loginAttempts}}
</div>
app.controller("mainController", ["$rootScope", "$scope", function ($rootScope, $scope) {
$scope.newsControllerData = {};
$scope.loginAttemptsControllerData = {};
// from mainController emit HandleNews upwards on the scope
$scope.OnNewButtonClick = function () {
$scope.newsControllerData.info = "Hello World";
$scope.$emit("HandleNews");
}
// from mainController emit HandleLoginAttempts upwards on the scope
$scope.OnLoginAttemptButtonClick = function () {
$scope.loginAttemptsControllerData.info = "login count = 4";
$scope.$emit("HandleLoginAttempts");
}
}]);
app.controller("newsController", ["$rootScope", "$scope", function ($rootScope, $scope) {
$scope.newsControllerData = {};
// when any controller calls HandleNews, i would listen
$rootScope.$on("HandleNews", function (evt, next, current) {
$scope.newsControllerData.News = evt.targetScope.newsControllerData.info;
});
}]);
app.controller("loginAttemptsController", ["$rootScope", "$scope", function ($rootScope, $scope) {
$scope.loginAttemptsControllerData = {};
// when any controller calls HandleLoginAttempts, i would listen
$rootScope.$on("HandleLoginAttempts", function (evt, next, current) {
$scope.loginAttemptsControllerData.loginAttempts = evt.targetScope.loginAttemptsControllerData.info;
});
}]);
|
How to implement retry (talking to view controller) button in a custom UIVIEW Swift
By : Chanaka Karunaratne
Date : March 29 2020, 07:55 AM
|
Angular UI router - does a nested view's controller automatically become a child of the parent view's controller?
By : Isaac Sarf
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further There are related Q & A: ui router - nested views with shared controller How do I share $scope data between states in angularjs ui-router? code :
.state("main", {
controller:'mainController',
controllerAs:'mainCtrl',
url:"/main",
templateUrl: "main_init.html"
})
.state("main.1", {
controller:'childController',
parent: 'main',
url:"/1",
templateUrl: 'form_1.html'
})
.state("main.2", {
controller:'childController',
parent: 'main',
url: "/2",
templateUrl: 'form_2.html'
})
app.controller('mainController', function ($scope) {
var Model = {Name : "xxx"}; // controller property Model
})
<div>
<h5>Child state FORM 2</h5>
<pre>{{mainCtrl.Model}}</pre>
Change the value in a child state FROM 2
<input ng-model="mainCtrl.Model.Name" />
</div>
|
How can I emit data from main controller to view controller in angular?
By : Bastiaan
Date : March 29 2020, 07:55 AM
To fix the issue you can do That's because $emit goes up the tree. Use $broadcast instead as it traverses the tree downwards.
|