angularjs ui-router – how to build master state which is global across app

The approach you took in your plunker is close. @ben-schwartz’s solution demonstrates how you’d set defaults in your root state for the three essentially-static views. The thing missing in your plunker is that your child states still need to reference the top container view. .state(‘root’,{ url: ”, views: { ‘header’: { templateUrl: ‘header.html’, controller: ‘HeaderCtrl’ …

Read more

AngularJS: Is ng-click “a good practice”? Why is there no ng-{event} in AngularJS?

Why is this one of the core concepts of AngularJS, if most people say this is “bad”? Well, people who really like Unobtrusive JavaScript might say it is bad. Angularians (and those with a flex background) see value in the more declarative approach. “Angular is built around the belief that declarative code is better than …

Read more

Create empty promise in angularjs?

Like Bixi wrote, you could use $q.when() which wraps a promise or a value into a promise. If what you pass to when() is a promise, that will get returned, otherwise a new promise is created which is resolved directly with the value you passed in. Something like this: var promise; if(!$scope.user){ promise = UserService.create(params); …

Read more

AngularJS How to dynamically add HTML and bind to controller

I would use the built-in ngInclude directive. In the example below, you don’t even need to write any javascript. The templates can just as easily live at a remote url. Here’s a working demo: <p>Select page content template via dropdown</p> <select ng-model=””> <option value=”page1″>Page 1</option> <option value=”page2″>Page 2</option> </select> <p>Set page content template via …

Read more

angularjs – using {{}} binding inside ng-src but ng-src doesn’t load

Changing the ng-src value is actually very simple. Like this: <html ng-app> <head> <script src=””></script> </head> <body> <img ng-src=”{{img_url}}”> <button ng-click=”img_url=”””>Click</button> </body> </html> Here is a jsFiddle of a working example:

Passing data to mdDialog

This guy always has the right answer: In short: ${ locals:{dataToPass: $scope.parentScopeData}, clickOutsideToClose: true, controllerAs: ‘ctrl’, templateUrl: ‘quotation/edit/’,//+edit_id, controller: mdDialogCtrl, }); var mdDialogCtrl = function ($scope, dataToPass) { $scope.mdDialogData = dataToPass } Pass the variable using the locals attribute in the passing object. These values will be injected into the controller not the $scope. …

Read more

AngularJs – ng-model in a SELECT

You can use the ng-selected directive on the option elements. It takes expression that if truthy will set the selected property. In this case: <option ng-selected=”data.unit ==” ng-repeat=”item in units” ng-value=””>{{item.label}}</option> Demo angular.module(“app”,[]).controller(“myCtrl”,function($scope) { $scope.units = [ {‘id’: 10, ‘label’: ‘test1’}, {‘id’: 27, ‘label’: ‘test2’}, {‘id’: 39, ‘label’: ‘test3’}, ] $ = { ‘id’: …

Read more