angularjs-scope

angular ng-show / ng-hide not working correctly with ng-bind-html

我们两清 提交于 2019-12-10 18:05:23
问题 I want to set ng-show or ng-hide for my elements in html string and pass it to view with ng-bind-html but ng-show / ng-hide not working and my element always visible. This is my controller code: $scope.my = { messageTrue: true, messageFalse: false }; $scope.HtmlContent = "<div ng-show='{{my.messageFalse}}'>This is incorrect (ng-show & my.messageFalse={{my.messageFalse}})</div> "; $scope.trustedHtml = $interpolate($scope.HtmlContent)($scope); And this is my view code: <div ng-show="my

How should I reference services in my controller functions without using scope?

♀尐吖头ヾ 提交于 2019-12-10 18:02:50
问题 After reading several articles on avoiding scope soup and referencing the Google Guidelines for building controllers I have been left with one burning question. How should I reference my injected dependencies within my controller? My approach thus far is to put the services on my object but I'm not exactly happy with that as now my services are exposed to the outside world (the template markup). What is the correct approach to build a controller without directly referencing $scope, and have

AngularJS scope values undefined in link

∥☆過路亽.° 提交于 2019-12-10 17:04:51
问题 I'm trying to figure out something with scope and link when a directive is initialized. I have a directive in a tree controller to display details at a branch point: <typelists sub="branch.subBranches[0]"></typelists> The (relevant parts of the) directive that handles that branch info are below: listsApp.directive( 'typelists', function($rootScope) { return { restrict: 'EA', replace: true, scope: { branch : '=sub' }, templateUrl: templateDir + '/typelists.html', link: function (scope, element

How to call function in ng-click which is defined in factory service

余生长醉 提交于 2019-12-10 16:24:35
问题 How can I call the function in ng-click which is defined inside a factory service, app.factory('MyFactory', [function () { return { setTest: function(test) { alert(test); } }; }]); app.controller('TestCtrl', ['$scope','MyFactory', function ($scope, MyFactory) { }]); <li><a href="#" ng-click="setTest('PHP')">PHP</a></li> <li><a href="#" ng-click="setTest('Javascript')">Javascript</a></li> 回答1: The method should be defined on your scope for it to be usable in bindings. In your controller you

AngularJS : Directive Isolated Scope Undefined

萝らか妹 提交于 2019-12-10 16:16:17
问题 I am writing a directive with an isolate scope with a two-way binding in AngularJS . However, I cannot seem to get the two-way binding to work. No matter what I do, the populate property on the isolate scope is always undefined (although the property does exist) instead of being the value it's supposed to be bound to. HTML: <html> <body ng-app="MyApp"> <div ng-controller="MyController"> {{data.dataProp}} <!-- demonstrates that data.dataProp is defined --> <scope-fail data-source="data

Does angularjs treates null as $scope.null?

半腔热情 提交于 2019-12-10 15:29:06
问题 Example for the question <div ng-show="bar !== null">hello</div> Is this evaluated in the scope as $scope.bar !== null or is it as this? $scope.bar !== $scope.null Note that in last case, $scope.null would be undefined and the example would seem to work right. Bonus: if bar = null then this happens // this does not work (shows hello) <div ng-show="bar !== null">hello</div> does not give the same result as // this works ok (does not show hello) <div ng-show="bar != null">hello</div> why does

Accessing the window from Angular expression

╄→гoц情女王★ 提交于 2019-12-10 14:59:10
问题 According to the developer guide I should be able to access the browser window from inside Angular expressions with $window . Unlike JavaScript, where names default to global window properties, Angular expressions have to use $window to refer to the global window object. For example, if you want to call alert(), which is defined on window, in an expression you must use $window.alert(). However I can't seem to access $window from expressions evaluated with $scope.$eval . Here are some outputs

Why formatters does not work with isolated scope?

怎甘沉沦 提交于 2019-12-10 14:24:33
问题 Why formatters does not work with isolated scope? Is this angular bug or I am doing something wrong? This contains isolates scope and does not work: http://jsfiddle.net/YbdXQ/56/ restrict: 'A', scope:{}, link: function(scope, elm, attrs, ctrl) { ctrl.$formatters.unshift(function(modelValue) { console.log("In formatters" + modelValue); return $filter('date')(modelValue); }); This does not contain isolated and scope works fine: http://jsfiddle.net/YbdXQ/57/ restrict: 'A', link: function(scope,

Isolate scope attributes defined with @ are undefined/disappear in directive's link function

寵の児 提交于 2019-12-10 13:57:27
问题 The directive has isolate scope, and the scope attributes are being passed with "@". This is how the directive is called: <div ng-init="classForIcon = 'vladClass'"></div> <div ng-init="textForIcon = 'Icon\'s text'"></div> <div ng-init="routeForIcon = 'www.google.com'"></div> <div ng-init="tooltipForIcon = 'my tooltip'"></div> <div ng-init="imageForIcon = 'images/HOME_ICON1.png'"></div> <rl-icon-widget icon-class="{{classForIcon}}" icon-text = "{{textForIcon}}" icon-tooltip="{{tooltipForIcon}}

How get AngularJS element by name?

老子叫甜甜 提交于 2019-12-10 13:33:41
问题 In my form validation there is part of server validations. So I should get back from the server list with the names of the fields and a string with the error in each of them. My idea was to write a general code knowledge to deal with all fields without knowing them in advance, by accessing them with their name. this is field for example: <!-- Email --> <div class="form-group" data-ng-class="{ 'has-error' : step1Form.email.$invalid && (!step1Form.email.$pristine || submitted) }"> <label>Email<