javascript - AngularJS - Pass some flag from html to controller -
i new angular js. stuck, , not find solution.
problem - have html code given below :
<div ng-controller="mycontroller" ng-model={{tt="a"}}> </div> <div ng-controller="mycontroller" ng-model={{tt="b"}}> </div> <div ng-controller="mycontroller" ng-model={{tt="c"}}> </div>
and controller code :
myapp.controller('mycontroller', function($scope) { if($scope.tt == "a") //do else if($scope.tt == "b) //do else })
note - html ng-model, wrote let know want.
question - want send controller html, can check value , conditionally.
this not best practice if want bring data in html angular can stash data property of window
inside of <script>
tag.
var app = angular.module('myapp',[]); app.controller('mainctrl', function($scope){ $scope.tt = window.data; })
<div ng-app='myapp'> <div ng-controller='mainctrl'> {{tt}} </div> </div> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.22/angular.min.js"></script> <script> window.data='abcd'; </script>
Comments
Post a Comment