Inject variables via ng-init to controller

后端 未结 3 857
感动是毒
感动是毒 2021-01-07 03:20

I want to inject the same variables with different values multiples times to the same controller. This is what I tried. What is a way to get different values in each call?

3条回答
  •  难免孤独
    2021-01-07 04:22

    Try this... As @tymeJV pointed out you need to use semicolons to separate the variable names in the HTML. You also need to use the $scope to reference the variables in the controller.

    html

         
        

    javascript

    var app = angular.module("myApp", []);
    
    app.controller("myCtrl", ["$scope",function($scope) {
        console.log($scope.test);
        console.log($scope.test1);
    }]);
    

提交回复
热议问题