1

I am currently stuck on hopefully a simple problem:

I have a controller.js

app.controller('WizardCtrl', function ($scope) {
  $scope.send = function() {
    console.log($scope.isPasswordChanged)
  }
});

My view.html

isPasswordChanged: {{ isPasswordChanged }} <br>
<update-password-field is-changed="isPasswordChanged"></update-password-field>
<button ng-click="send()"></button>

My directive.js

app.directive('updatePasswordField', function () {
  return {
    restrict: 'E',
    scope: {
      isChanged: "="
    },
    templateUrl: "password-field-directive.html",
    link: function (scope) {
        // some magic to set isChanged value to true of false 
    }
  }
});

So in my view.html I can see the changes of "isPasswordChanged", to it is somehow in my $scope, but if I console.log($scope) the "isPasswordChanged" is not present.

Why and how to make it present?

11
  • 2
    where did u put the console.log($scope) ? Commented Sep 14, 2015 at 12:52
  • when you call send function? can you provide working sample? Commented Sep 14, 2015 at 12:52
  • @K.Toress in my send() function, I updated my view.html Commented Sep 14, 2015 at 12:55
  • @Grundy I updates my view.html Commented Sep 14, 2015 at 12:55
  • I think @Craig has the answer Commented Sep 14, 2015 at 12:56

2 Answers 2

3

I think you need to include the $scope in your controller's function(). In other words:

app.controller('WizardCtrl', ['$scope', function ($scope) {

Otherwise I don't believe it will work.

Sign up to request clarification or add additional context in comments.

4 Comments

I think it should be app.controller('WizardCtrl', function ($scope) {.. ? isn't it?
@K.Toress Ok I've fixed it.
@Craig regarding to thes topic, I can inject $scope in my directive stackoverflow.com/questions/19311102/…
@Craig sorry, it was only an example, but my real code contains $scope in my controller. I just updated the code.
0

Turned out it is a problem with probably my structure.

I changed

is-confirmed="isPasswordConfirmed"

to

is-confirmed="ui.isPasswordConfirmed"

"ui" is an empty object I defined in my $scope.

And its working. I tried a stand alone example

http://plnkr.co/edit/bkMZTEWgkrmVfxqiYCcB?p=preview

But it is working without this changes, it also might be a mismatch with angular version.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.