Tuesday, September 26, 2017

get value from custom directive in a controller function – AngularJS

I have the following code, i want to receive the ng-module value from custom directive in the controller function:

The getName function is the function when i am trying to get the value..

'use strict';

angular
.module('app', [])
.controller("Controller", function ($scope) {
$scope.getName = function() {
return $scope.name;
};
})
.controller("EditController", function($scope) {
$scope.editingMode = true;
})
.directive("newName", function ($parse) {
return {
template: 'Write name: <input type="text" ng-model="name">'
};
});


<html ng-app="app">
  <head>
    <meta charset="utf-8">
    <title>Angular</title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width">
  </head>
  <body>

    <div ng-controller="Controller">
      <h1>Hello, </h1>

      <div ng-controller="EditController">
        <new-name ng-show="editingMode"></new-name>
      </div>
    </div>

  </body>
</html>

Can somebody help me?

Source: AngularJS



from Angular Questions https://angularquestions.com/2017/09/26/get-value-from-custom-directive-in-a-controller-function-angularjs/
via @lzomedia #developer #freelance #web

No comments:

Post a Comment