1

I'm new at angularjs and i'm having some serious problems lol...

I've something like this that is working so i don't know whats the problem with this code.. can you help me pls?

Here is it: Basicly the scope.create does not work.. it doesn't even enter in the function..

<!DOCTYPE html>
<html>`enter code here`
<head>
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-resource/1.6.5/angular-resource.min.js"></script>
<script>

var app = angular.module('myAppDevice', ['ngResource']);

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

    $scope.create = function(a){
        console.log("ola");
        Device = $resource(
                "http://localhost:8080/userapi/postdevice/:userId/:deviceType",
                {},
                {save: {method:'POST',isArray:false, params: {userId: '@userId',deviceType:'@deviceType'}}}
        );


        $scope.Message = Device.save({externalId: $scope.deviceForm.userId, deviceType:a});

        $scope.deviceForm.userId = "";

    };



}]); 

function func(){
    console.log("ole");
}


app.controller('deviceCtrl', function($scope) {
    $scope.myVar = false;
    $scope.toggle = function() {
        $scope.myVar = !$scope.myVar;
    };
});



</script>
</head>

<body ng-app="myAppDevice">

    <div ng-controller="deviceCtrl">
        <form name="deviceForm">

            <div class="form-group">    
                <img id="device" alt="sensor"
                    src="http://www.solucoesindustriais.com.br/images/produtos/imagens_10048/p_sensor-de-movimento-para-porta-12.jpg"
                    width="300" height="150" ng-click="toggle()" />
            </div>
   <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
            <div class="form-group">
                <p ng-show="myVar">
                    userId: <input ng-model="deviceForm.userId" type=text>
                </p>
            </div>

            <div class="btn-wrapper">
                <div class="row-gutter-5">
                    <div class="col-md-4 col-xs-6 col-sm-6">
                        <button class="btn btn_blue" type="button"
                            data-ng-click="create(lamp)" id="Create">Create</button>
                    </div>
                </div>
            </div>
        </form>
    </div>

</body>
</html>

Thanks

[EDIT] Thanks guys!! it was solved by removing the controller as you said.. i was starting to be desperate !!

1
  • Post your html. Also why you have two deviceCtrl? Commented Jul 18, 2017 at 10:12

2 Answers 2

1

you are duplicating your controller by calling twice "deviceCtrl". Keep it once and try. As the code compiles and execute the latest deviceCtrl will get called and hence the $scope.create() not getting called.

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

Comments

0

Just remove Second deviceCtrl

app.controller('deviceCtrl', function($scope) {
    $scope.myVar = false;
    $scope.toggle = function() {
        $scope.myVar = !$scope.myVar;
    };
});

Here is an working example.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.