1

Let's take this simple example. When I build it on a page not in Sharepoint context it works. Within Sharepoint context it doesn't work correctly. If I bind two fields to the same object they get updated when i change one, so the binding works as supposed. But when I call a function using a button with ng-click, all the objects result to be undefined.

My snippets:

HTML

   <div class="mainTable" ng-app="app" ng-controller="partnerProvisionEmailCtrl">
        <input type="text" ng-model="year" />
        <input type="text" ng-model="year" />
        <input type="button" value="Send Email" ng-click="sendEmail()"/>
    </div>

SCRIPT (App.js)

'use strict';

var app = angular.module('app', ['appControllers']);

SCRIPT (Controller.js)

"use strict";

var appControllers = angular.module('appControllers', []);

appControllers.controller('partnerProvisionEmailCtrl', ['$scope', '$http', function ($scope, $http) {

    $scope.sendEmail = function(){
        // $scope.year is undefined!!!!
    }
}]);

My guess is that there is something in Sharepoint javascript part that creates conflict...Outside Sharepoint i get the right value. Any ideas?

EDIT: I repeat, as standalone my code works! In Sharepoint it doesn't!

  • 2
    is this complete snippet of your code? with no controller and module defined? you can't make angularJS work like that – Akshay Randive May 15 '15 at 8:38
  • Come on guys...how could i say that the $scope.year is undefined? Furthermore, i wrote ...two fields to the same object they get updated when i change one.... Do you really want the complete code? – Emaborsa May 15 '15 at 8:59
  • So...for your interest i added the part to "complete" it. – Emaborsa May 15 '15 at 9:14
  • 1
    I read all your code, and the code is wrong – eirikb May 15 '15 at 9:48
  • 1
    Here is a plnkr with your code (doesn't work) , and here is a plnkr with my suggestion. I understand you probably have something like the last one working for you, I just made a comment about your code, which is all I can see. I can't see your wiring, your setup, your angular version, your SharePoint version. I can however tell you I have several Angular-based solutions working in several SP environments – eirikb May 15 '15 at 9:55
0

it's working for me without any error in sharepoint (tried it in wiki as well as html page) please check for error in browser console, make sure you have angular.min.js.map in same folder where angular.js is stored on local pc as in it will refer to previous one internally

HTML

<div ng-app="app"  ng-controller="partnerProvisionEmailCtrl">
 Enter Year:
    <input type="text" ng-model="year"/>
     <input type="text" ng-model="year"/>
    <button ng-click='sendEmail()'>greet</button>
  <hr/>
  {{year}}
</div>

App.js

'use strict';

var app = angular.module('app', ['appControllers']);

Controller.js

  "use strict";
var appControllers = angular.module('appControllers', []);
appControllers.controller('partnerProvisionEmailCtrl', ['$scope', '$http', function ($scope, $http) {
    $scope.sendEmail = function(){
        // $scope.year is undefined!!!!
        alert($scope.year)
    }
}]);
  • I don't know what to say. In my case it doesn't work... – Emaborsa May 15 '15 at 12:13
  • open your SharePoint site in Chrome press F12 hit the URL and check if you have error in browser console – Akshay Randive May 15 '15 at 12:47
  • I already checked it. No errors. – Emaborsa May 15 '15 at 13:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.