0

I would like to have a ng-if evaluate a viewpoint.

For example

<div ng-if="viewPort=='SM'">

Or, maybe just a $watch and then I can set a variable that's in the $scope

I know I could do some magic with events etc, but I am looking for the angler way if one exists.

EDIT

Thinking about how this would work, I presume I would need a service and a way to hook into viewport changes so my controller can update the model so the view can react.

Steve Drake
  • 1,968
  • 2
  • 19
  • 41
  • ng-if does exist in angular.Are you asking about ng-if or am I getting your question wrong? – Rishi Apr 28 '15 at 12:02
  • I would like to be able to evaluate the bootstrap viewPort, I could probs code it all up but it would be nice if someone had used a trusted open source module before. – Steve Drake Apr 28 '15 at 12:04
  • 1
    May be you have already seen this post. I think it does what you are looking for (or something close enough) http://stackoverflow.com/questions/18575582/how-to-detect-responsive-breakpoints-of-twitter-bootstrap-3-using-javascript – Chintana Meegamarachchi Apr 28 '15 at 13:06
  • that is useful, but I would love a service that just did all that. – Steve Drake Apr 28 '15 at 15:22

1 Answers1

0

ng-if automatically evaluates the expression inside as it creates a watcher. You don't need any module, any 3rd party .... anything basically. That's just plain 2-way data binding. In your controller just do:

$scope.viewport='';
$timeout(function () {
    $scope.viewport='SM'
}, 5000);

After 5 seconds you will see your div appearing. Just mind that you'll need to inject both $scope and $timeout.

Adrian Neatu
  • 1,989
  • 2
  • 19
  • 34
  • yep, I understand but I need something that does something when the viewport changes, as in http://codepen.io/dih/full/ivECj (that's from the example in the comment on the Q) but i think a service would wrap it up better. – Steve Drake Apr 28 '15 at 15:24
  • I understand what you mean. There isn't anything like that in the core Angular however I would suggest you to create a directive and use the window.resize event to know when the size changes. – Adrian Neatu Apr 29 '15 at 07:12